Sunday, January 3, 2010

passing parameter through h:commandButton in JSF

In JSF, <h:commandButton> doesnot support <f:param> so that we cannot use it to pass parameter. However, it is supported in <h:commandLink> . So, in order to pass parameter through , <h:commandButton> we can use <f:attribute> . An example is shown to demonstrate this:

<h:commandButton actionListener=#{bean.callAction}/>
<f:attribute name="parameterName" value="parameterValue"/>
</h:commandButton>

In backing bean,

public void callAction(ActionEvent ae){
String paramValue = (String) ae.getComponent().getAttributes().get("parameterName");
System.out.println("Parameter value is :: "+paramValue);
}

The output is -
Parameter value is :: parameterValue

which is in the value attribute of f:attribute tag.

No comments: