JSF 2.0: actionListener action in primefaces with setPropertyActionListener

Today I had a problem with a PrimeFaces-CommandButton which has a setPropertyActionListener and an actionListener attached to it.

The problem was that the actionListener is called before the setPropertyActionListener, which resulted in the behavior that the Method could only access the set property the second time it got executed.

Replacing the actionListener with an action did the trick (while the action-Method returns null, so there’s no page-transition).

I still don’t know if this is an expected behavior, but it does work, so I’ll stick with this for now.

JSF Implementation is Mojarra 2.0.4-b09 with PrimeFaces 3

 

Finally got the answer:

The actionListener runs always before theaction. If there are multiple action listeners, then they run in the same order as they have been registered.

 <f:setPropertyActionListener> is one kind of actionListener . In general,actionListener always get fired before action. That’s why it always work with action.

In my case

<p:commandButton id=”selectButton” actionListener=”#{gameManager.onRowSelect}”  title=”Join” value=”Join”>

<f:setPropertyActionListener value=”#{game}” target=”#{gameManager.currentGame}” />

</p:commandButton>

The onRowSelect will always be executed before the currentGame value being set. Therefore, change it to action would work.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s