f:param doesn't work with h:commandButton

主宰稳场 提交于 2019-12-22 13:01:22

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/8334467/fparam-doesnt-work-with-hcommandbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!