With the button you associate an action
, which is a method in the backing bean
You can set params in the backing bean and read them when you press the button, from the method linked to action
. The action method should return a String
, which will be read by the Navigation Handler to check if it has to move to a new page, according to the configuration in the faces-config.xml
.
<h:form>
<h:commandButton value="Press here" action="#{myBean.action}">
<f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" />
<f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" />
</h:commandButton>
</h:form>
Backing bean:
package mypackage;
public class MyBean {
// Init --------------------------------------------------------------------------------------
private String propertyName1;
private String propertyName2;
// Actions -----------------------------------------------------------------------------------
public void action() {
System.out.println("propertyName1: " + propertyName1);
System.out.println("propertyName2: " + propertyName2);
}
// Setters -----------------------------------------------------------------------------------
public void setPropertyName1(String propertyName1) {
this.propertyName1 = propertyName1;
}
public void setPropertyName2(String propertyName2) {
this.propertyName2 = propertyName2;
}
}
This example is taken from here (BalusC blog, probably he will come and tell you to check that link but I'm faster! :P)
Of course to achive this the bean has to be set as session scoped
. If you want it to be request scoped
you can follow the steps here