f:与trinidad 2一起使用时,param无法正常工作

时间:2012-01-23 12:51:58

标签: jsf-2 trinidad

我正在使用JSF 2 Trinidad 2(MyFaces)并尝试在命令按钮中使用f:param

<tr:commandButton text="Submit" action={backingBean.actionSubmit}>
<f:param name="isSubmit" value="Yes" />
</tr:commandButton>

基本上我正在尝试传递提交按钮的参数值,并且仅在单击“提交”按钮时执行验证,将条件添加到输入元素的必需属性以检查提交按钮。

有没有办法识别JSF2 / Trinidad2中的特定按钮点击,以便我可以在验证方法中检查该按钮的点击。

2 个答案:

答案 0 :(得分:0)

我正在使用JSF 1.2,但我认为它在JSF 2.0中的工作方式相同。

对于commandButton,请使用actionListener而不是action。

<tr:commandButton text="Submit" actionListener={backingBean.actionSubmit}> 

在您的bean中,您可以获得按钮的ID:

public void actionSubmit(ActionEvent event)
{
   event.getComponent().getId();
}

答案 1 :(得分:0)

您可以考虑使用<tr:setActionListener/>。在你的情况下,你可以使用类似的东西:

<tr:commandButton text="Submit" action="#{backingBean.actionSubmit}">
  <tr:setActionListener from="submit" to="#{backingBean.pressedButton}" />
</tr:commandButton>

基本上,您可以使用它将对象从from属性复制到to属性。请注意,您也可以在from属性中使用EL(#{someBean.someObject})。

在你的支持bean中,你需要添加一个名为String的{​​{1}}成员(带有getter和setter)。现在,您可以在pressedButton

中使用以下代码
actionSubmit