我想在进一步处理之前使用多个 Action 监听器来设置两个支持 bean 的状态
第一种方式:
<p:commandButton process="@this" >
<f:attribute name="key" value="#{node.getIdTestGroup()}" />
<f:actionListener binding="#{testController.nodeListener}" />
<f:actionListener binding="#{testDeviceGroupController.prepareCreate}" />
</p:commandButton>
它给出了一个异常(exception):
警告:/testGroup/List.xhtml @26,88 binding="#{testController.nodeListener()}":找不到方法 nodeListener
javax.el.ELException:/testGroup/List.xhtml @26,88 binding="#{testController.nodeListener()}": 找不到方法 nodeListener
第二种方式:
<p:commandButton process="@this" >
<f:attribute name="key" value="#{node.getIdTestGroup()}" />
<f:actionListener binding="#{testController.nodeListener(event)}" />
<f:actionListener binding="#{testDeviceGroupController.prepareCreate(event)}" />
</p:commandButton>
nodeListener 和 prepareCreate 方法上的事件为空
怎么做才对?
最佳答案
我看到你促进了猜测它是如何工作的传统方法,使用裸直觉和随机关联 - 然后 - 行动 - 惊讶 :-)f:actionListener
仅允许您将整个对象添加为观察者,而不是任意方法。您可以使用 type
属性来指定类名(它将由 JSF 实例化)或 binding
属性来提供您自己创建的对象的实例(不是方法!)。对象必须实现 javax.faces.event.ActionListener
.
您的第二次尝试( testDeviceGroupController.prepareCreate(event)
)在许多层面上都是错误的,但关键是调用这些方法不是为了处理您的操作,而是为了创建 Actionlistener
实例。
你有几个选择:
像这样:
public ActionListener createActionListener() {
return new ActionListener() {
@Override
public void processAction(ActionEvent event) throws AbortProcessingException {
System.out.println("here I have both the event object, and access to the enclosing bean");
}
};
}
并像这样使用它:
<h:commandButton>
<f:actionListener binding="#{whateverBean.createActionListener()}"/>
</h:commandButton>
关于jsf - JSF 中的多个 Action 监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16374012/