Skip to content

Instantly share code, notes, and snippets.

@jamestrandung
Last active December 15, 2015 17:59
Show Gist options
  • Save jamestrandung/5300085 to your computer and use it in GitHub Desktop.
Save jamestrandung/5300085 to your computer and use it in GitHub Desktop.
The order of Action and Listener in JSF
package my.beanBag;
@ManagedBean(name = "mrBean")
@RequestScoped
public class MrBean implements ActionListener {
private String type;
public void triggerActionListener() {
System.out.println("MrBean is called by buttons' actionListener.");
}
public void triggerAction() {
System.out.println("MrBean is called by button's action.");
}
public void setType(String type) {
System.out.println("MrBean is called by <f:setPropertyActionListener>.");
}
@Override
public void processAction(ActionEvent event) throws AbortProcessingException {
System.out.println("MrBean is called by <f:actionListener>.");
}
}
<h:commandButton value="Test" actionListener="#{mrBean.triggerActionListener}" action="#{mrBean.triggerAction}" >
<f:setPropertyActionListener target="#{mrBean.type}" value="Green bean" />
<f:actionListener type="my.beanBag.MrBean" />
</h:commandButton>
<--- Start of Console --->
MrBean is called by buttons' actionListener.
MrBean is called by <f:setPropertyActionListener>.
MrBean is called by <f:actionListener>.
MrBean is called by button's action.
<--- End of Console --->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment