1

I have a problem with a form not triggering its commandButton action method. When I submit the form without prior update (not selecting any node in the tree), the method triggers just fine.

As soon as the form is Ajax-updated, the commandButton won't call its action anymore.

Here is the JSF code:

<p:layoutUnit position="center">
    <p:tree orientation="horizontal" value="#{flightTypeController.tree}" var="node"
        selectionMode="single" selection="#{flightTypeController.selectedNode}">
        <p:ajax event="select" listener="#{flightTypeController.onNodeSelect}" update=":typesTree"/>

        <p:treeNode>
            <h:outputText value="#{node.name}"/>
        </p:treeNode>
    </p:tree>

    <h:form id="typesTree">
        <p:inputText disabled="true" id="outputParent" value="#{flightTypeController.selectedOne.name}"/>
        <p:inputText id="outputName" value="#{flightTypeController.current.name}"/>


        <p:commandButton ajax="false" icon="ui-icon-disk" value="#{bundle.general_create}" action="#{flightTypeController.create()}"/>
    </h:form>
</p:layoutUnit>

And the java listener:

public void onNodeSelect(final NodeSelectEvent event) {
    final Object res = event.getTreeNode().getData();
    if (res instanceof FlightType) {
        selectedOne = (FlightType) res;
    } else {
        selectedOne = null;
    }
}

I already check BalusC's bible and JS Fix but without success.

I've seen similar behaviours quite often (and had to find workarounds) so I might have misunderstood something fundamental.

Oh, yes, I checked multiple times : no nested forms in my code.

4

1 回答 1

1

The JS fix which you found is hooking on jsf.ajax.addOnEvent which is only triggered by <f:ajax>, not by PrimeFaces components which use jQuery under the covers.

To cover PrimeFaces ajax requests as well, grab the current version of the JS fix (I have recently updated that post) and add the following to apply this fix on jQuery ajax requests as well:

$(document).ajaxComplete(function(event, xhr, options) {
    if (typeof xhr.responseXML != 'undefined') { // It's undefined when plain $.ajax(), $.get(), etc is used instead of PrimeFaces ajax.
        fixViewState(xhr.responseXML);
    }
}

Disclaimer: I haven't tried your specific use case. But, theoretically, it should solve your problem.

于 2013-09-13T14:16:52.407 回答