Hossein Boka
Hossein Boka

Reputation: 386

f:param doesn't work with h:commandButton

i'm using eclipse 3.6.2 (Helios) , Tomcat 7 , MyFaces 1.2.9

i have no problem when i use f:param into the h:commandLink but when i put f:param into h:commandButton it doesn't work . what's the problem ?

this sample work fine :

<h:commandLink value="Click here" action="#{myBean.action}">
<f:param name="parameterName1" value="parameterValue1" />
<f:param name="parameterName2" value="parameterValue2" />
</h:commandLink>

but it doesn't

<h:commandButton value="Click here" action="#{myBean.action}">
<f:param name="parameterName1" value="parameterValue1" />
<f:param name="parameterName2" value="parameterValue2" />
</h:commandButton>

Upvotes: 3

Views: 7153

Answers (1)

BalusC
BalusC

Reputation: 1108537

In JSF 1.x, the <f:param> is only supported in <h:commandLink>, <h:outputLink> and <h:outputFormat>, not in <h:commandButton>. That support is only in JSF 2.0 and newer.

You have at least 4 options:

  1. Use <h:commandLink> instead. If necessary use CSS to style it to look like a button. See for an example also JSF commandButton URL parameters.

  2. Use <f:attribute> or <f:setPropertyActionListener> instead. See also Communication in JSF.

  3. Pass them as method arguments action="#{myBean.action('param1', 'param2')}". Tomcat 7 is a servlet 3.0 container which supports EL 2.2 which in turn supports passing method arguments. You only need to make sure that your web.xml is declared conform Servlet 3.0. See also Invoking methods with parameters by EL in JSF 1.2.

  4. Upgrade to JSF 2.0. It offers so much advantages over JSF 1.x. See also Migrating from JSF 1.2 to JSF 2.0 and Communication in JSF 2.0.

Upvotes: 9

Related Questions