【发布时间】:2011-12-16 07:03:09
【问题描述】:
<h:commandButton>的动作中是否可以执行两个方法?
例如,
<h:commandButton action="#{bean.methodOne();bean.methodTwo();}" />
【问题讨论】:
<h:commandButton>的动作中是否可以执行两个方法?
例如,
<h:commandButton action="#{bean.methodOne();bean.methodTwo();}" />
【问题讨论】:
你可以像这样使用f:actionListener。
<h:commandButton action="#{bean.methodOne()}">
<f:actionListener binding="#{bean.methodTwo()}" />
</h:commandButton>
您可以根据需要添加任意数量的f:actionListener 元素。
【讨论】:
在你的bean中添加一个methodThree:
public Object methodThree() {
methodOne();
methodTwo();
return someThing;
}
并从 JSF 页面调用此方法。
【讨论】:
h:commandButton action 属性的 Mojarra javadoc:MethodExpression 表示用户激活此组件时要调用的应用程序操作。表达式必须评估为不带参数的公共方法,并返回一个对象(调用其 toString() 以得出逻辑结果),该对象被传递给此应用程序的 NavigationHandler。
接受的答案对我来说已经很接近了,但是分号引发了解析异常。以下代码有效:
<h:commandButton>
<f:actionListener binding="#{bean.methodTwo()}" />
</h:commandButton>
【讨论】: