f:param不适用于h:commandButton [英] f:param doesn't work with h:commandButton

查看:150
本文介绍了f:param不适用于h:commandButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用eclipse 3.6.2(Helios),Tomcat 7,MyFaces 1.2.9



我没有问题,当我使用f:param进入h :commandLink但是当我把f:param进入h:commandButton它不工作。有什么问题?



此示例工作正常:

  h:commandLink value =点击这里action =#{myBean.action}> 
< f:param name =parameterName1value =parameterValue1/>
< f:param name =parameterName2value =parameterValue2/>
< / h:commandLink>

但它不

 < h:commandButton value =点击这里action =#{myBean.action}> 
< f:param name =parameterName1value =parameterValue1/>
< f:param name =parameterName2value =parameterValue2/>
< / h:commandButton>


解决方案

在JSF 1.x中,<$ c $仅在< h:commandLink> < h:outputLink>中支持c>< f:param> ; 和< h:outputFormat> ,不在< h:commandButton> 。这种支持只能在JSF 2.0和更新版本中。



您至少有4个选项:


  1. 代替使用< h:commandLink> 。如果需要,使用CSS将其设计为看起来像一个按钮。另见 JSF命令按钮URL参数


  2. 使用< f:attribute> < f:setPropertyActionListener> 而不是。另请参见 JSF中的通讯


  3. 将它们作为方法参数传递 action =#{myBean.action('param1','param2')}。 Tomcat 7是一个支持EL 2.2的servlet 3.0容器,它依次支持传递方法参数。您只需确保您的 web.xml 声明符合Servlet 3.0。另请参阅使用JS中的EL调用参数方法1.2


  4. 升级到JSF 2.0。它比JSF 1.x提供了如此多的优势。另请参阅从JSF 1.2迁移到JSF 2.0 JSF 2.0中的通讯



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>

解决方案

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.

这篇关于f:param不适用于h:commandButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆