eclipse - f :param doesn't work with h:commandButton

标签 eclipse jsf tomcat7 myfaces

我正在使用 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 .
  • 升级到 JSF 2.0。与 JSF 1.x 相比,它提供了很多优势。另见 Migrating from JSF 1.2 to JSF 2.0Communication in JSF 2.0 .
  • 关于eclipse - f :param doesn't work with h:commandButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8334467/

    相关文章:

    android - 图形处理异常

    java - 将通用类注释为 JSF 托管 bean

    java - 未能执行目标 org.codehaus.mojo :tomcat-maven-plugin:1. 1:deploy (default-cli)

    eclipse - 在Spring,Maven和Eclipse中处理XML文件中的属性值的最佳方法

    PHP开发环境最佳实践

    jsf - 在 ManagedProperty 中使用 ResourceBundle 中的属性

    JSF 1.2 : How to keep request scoped managed bean alive across postbacks on same view?

    java - Tomcat 7 和 Spring boot war 启动

    ssl - JSSE 的 Tomcat SSL 配置 - 什么是 sslProtocol 属性

    java - 将 context.xml 与 Eclipse WTP 放在哪里?