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");

[1574 byte] By [nirav_p_assara] at [2007-11-27 11:36:45]
# 1

The f:param adds query parameters to the request URI and this can only be used in links.

If you want to pass parameters along h:commandButton, then use the f:attribute instead.

Also see http://balusc.xs4all.nl/srv/dev-jep-com.html

BalusCa at 2007-7-29 17:10:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...