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.

Community
  • 1
  • 1
Psyx
  • 758
  • 1
  • 9
  • 15

1 Answers1

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks, I tried that, and fixViewState is called properly, however, the `getViewState(responseXML)` returns null (my response seems to have an `update` element). – Psyx Sep 13 '13 at 16:55
  • Which PF version? The response should contain ``. – BalusC Sep 13 '13 at 17:00
  • PF 3.5. `` is present in the response. – Psyx Sep 13 '13 at 17:09
  • Sorry, that script works for me with 3.5. Even more, it's live in use at among others zeef.com. Can you please do a bit more debugging on your side? Inside `getViewState()`, what's the `updates.length`? What does `update.getAttribute("id")` return for each of them? Can you tell the browser make/version? (although that should hardly be the problem) – BalusC Sep 13 '13 at 17:12
  • Yes, I'll do some more debugging on my side. The confirmation that it's probably related to a spec-bug soon to be fixed is almost good enough for me ;). – Psyx Sep 13 '13 at 18:03