I would like that when the user clicks on a button 2 things happen :
- First a
setPropertyActionListeneris triggered, to update a property of my bean - Then an ajax call is made to execute a method from the bean
It seems that I must choose between the f:setPropertyActionListener tag and the f:ajax tag to nest inside the commandButton tag.
Is there a way to execute both the ajax call and the property update at the same time?
Thanks a lot!
EDIT : I forgot to mention I don’t want a form execution, I want to use the ajax listener, here is my code :
<h:commandLink styleClass="blue-button" value="+">
<f:setPropertyActionListener target="#{tvShowForm.selected}" value="#{tvShow.externalId}" />
<f:ajax event="click" listener="#{tvShowForm.add}" />
</h:commandLink>
With this code the f:setPropertyActionListener is not executed.
EDIT 2 :
I modified my code to the folowing, using action form method instead of listener. Now it works only if I don’t specify an event attribute on the ajax tag, but when I specify one, the action method is not executed.
<h:commandLink action="#{tvShowForm.add}" styleClass="blue-button" value="+">
<f:setPropertyActionListener target="#{tvShowForm.selected}" value="#{tvShow.externalId}" />
<f:ajax event="click" />
</h:commandLink>
Works just for me with Mojarra 2.1.3 on Tomcat 7.0.19 and Glassfish 3.1.1.
I used this relevant piece of the view:
with this relevant piece of the bean:
which prints the following on the ajax submit:
Your problem is caused by something else which you left out the question.
Update: as per your update
I really don’t see why you don’t want “a form execution”. You are submitting the form. You’ve only left out the action method and you’re doing the business job in the ajax event listener instead. The action listener methods aren’t intented to do any business job, they’re for at highest some self-containing processing or logging job. The model-dependent business job should be done in the action method, there it is for.