Search code examples
ajaxjsfjsf-2.2myfaces

Call order of h:commandLink action and f:ajax listener


Here is my markup:

<h:commandLink value="#{partial}" action="#{hello.setCurrentPartial(partial)}">
    <f:ajax render="include" listener="#{hello.renderFragments}"/>
</h:commandLink>

I tried to run this page in Mojarra-2.2.8(wildfly 8.2.0.Final built-in) and MyFaces-2.2.7(installed as guided here). Surprisingly, when the link is clicked, mojarra calls hello.renderFragments first and then hello.setCurrentPartial, but MyFaces takes the opposite order, i.e., hello.setCurrentPartial is called first.

So my question is whether there is a definition of the call order of action and ajax listener in JSF Spec. Which implementation is correct if the order is defined?


Solution

  • As per the EG discussion, there's agreement on Mojarra behavior being correct as it's in line with how actionListener/action work. The MyFaces guy has created an issue on it and it's expected that this will be fixed for next MyFaces release. And, the JSF spec should be more explicit in this, this will be worked on.

    In the meanwhile, if you want to have the same behavior in both Mojarra and MyFaces as to the method invocation order, move the <f:ajax listener> to <h:commandLink actionListener>.

    <h:commandLink value="#{partial}" actionListener="#{hello.renderFragments}" action="#{hello.setCurrentPartial(partial)}">
        <f:ajax render="include" />
    </h:commandLink>
    

    See also: