我正在使用 eclipse 3.6.2 (Helios) 、Tomcat 7、MyFaces 1.2.9
当我在 h:commandLink 中使用 f:param 时我没有问题,但是当我将 f:param 放入 h:commandButton 时它不起作用。有什么问题 ?
这个样本工作正常:
<h:commandLink value="Click here" action="#{myBean.action}">
<f:param name="parameterName1" value="parameterValue1" />
<f:param name="parameterName2" value="parameterValue2" />
</h:commandLink>
但它没有
<h:commandButton value="Click here" action="#{myBean.action}">
<f:param name="parameterName1" value="parameterValue1" />
<f:param name="parameterName2" value="parameterValue2" />
</h:commandButton>
最佳答案
在 JSF 1.x 中,<f:param>
仅在 <h:commandLink>
中受支持, <h:outputLink>
和 <h:outputFormat>
,不在 <h:commandButton>
.该支持仅在 JSF 2.0 和更新版本中提供。
您至少有 4 个选择:
<h:commandLink>
反而。如有必要,请使用 CSS 将其样式设置为看起来像一个按钮。参见示例 JSF commandButton URL parameters . <f:attribute>
或 <f:setPropertyActionListener>
反而。另见 Communication in JSF . action="#{myBean.action('param1', 'param2')}"
. Tomcat 7 是一个 servlet 3.0 容器,它支持 EL 2.2,而后者又支持传递方法参数。您只需要确保您的 web.xml
声明符合 Servlet 3.0。另见 Invoking methods with parameters by EL in JSF 1.2 . 关于eclipse - f :param doesn't work with h:commandButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8334467/