At a customer we have portals build with JSF 1.2, yeah I know ;-). Today is was interesting to found a solution for a problem.
In JSF 1.x there is a limitation of the Expression Language. It is not possible to pass parameters in methods in EL to controller bean.
I found a nice workaround for this limitation by using the setPropertyActionListener
Below is a button where this ActionListner is used
<h:form> <h:commandLink value="Click here" action="#{myBean.action}"> <f:setPropertyActionListener target="#{myBean.propertyName1}" value="propertyValue1" /> <f:setPropertyActionListener target="#{myBean.propertyName2}" value="propertyValue2" /> </h:commandLink> <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>
And this connected to the managed bean.
public class MyBean { private String propertyName1; private String propertyName2; public void action() { System.out.println("propertyName1: " + propertyName1); System.out.println("propertyName2: " + propertyName2); } public void setPropertyName1(String propertyName1) { this.propertyName1 = propertyName1; } public void setPropertyName2(String propertyName2) { this.propertyName2 = propertyName2; } }
Happy coding….
Tags: development, jsf