12

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?

Tiny
  • 24,933
  • 92
  • 299
  • 571
xiefei
  • 6,313
  • 2
  • 23
  • 43
  • This is indeed unexpected. As workaround, move `` to ``. I'll ask the JSF spec guys about this difference. – BalusC Mar 06 '15 at 15:24
  • @BalusC I guess the mojarra behavior is the desired one (please correct me as I'm not really sure), shouldn't listeners get invoked before the action method ? – Tarik Mar 06 '15 at 16:08
  • 1
    @Tarik: I can't find a reference in the spec about this behavior, but Mojarra behavior is indeed more intuitive/natural/expected. First listeners and then finally action, exactly like how actionListener/action work. I left the EG a [mail](https://java.net/projects/javaserverfaces-spec-public/lists/jsr372-experts/archive/2015-03/message/12). – BalusC Mar 06 '15 at 16:09
  • @BalusC Ok great, BTW you just got a first reply – Tarik Mar 06 '15 at 16:35
  • @Tarik: Yup, was just my colleague mentioning an agreement. – BalusC Mar 06 '15 at 16:36

1 Answers1

5

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:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • Quick response and thorough explanation of the problem and the solution both as always. If there is only one reason to do JSF, it is @BalusC. – xiefei Mar 07 '15 at 02:02
  • You're welcome and thank you for questioning this discrepancy, it only makes JSF better. – BalusC Mar 07 '15 at 10:51