Cannot have F:param within a h:commandButton
2:52 PM 7/24/2007
by Nirav Assar
Overview
It was discovered that with the component h:commandButton, JSF does not work when you embed an f:param and try and pass it through the request. However this does work with h:commandLink. The reason for this lies in how the Renderer classes in JSF vary when rendering a button versus a link. This is an often encountered issue and people have posted about this.
Example
We are able to get a parameter through the FacesContext request map if we do this:
<h:commandLink action="#{bean.go}">
<h:outputText value="Hit Me" />
<f:param name="itemId" value="#{bean.itemId}" />
</h:commandLink>
Then in a managed bean (java), we can make a call such as:
String itemId = (String) FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("itemId");
This results is the parameter being recieved in the backing bean.
However the following does not work:
<h:commandLink value="Hit Me" action="#{bean.go}">
<f:param name="itemId" value="#{bean.itemId}" />
</h:commandLink>
...in Java Backing Bean
String itemId = (String) FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap().get("itemId");

