JSF - actionListener tag calls method which doesn't take an ActionEvent parameter

时间秒杀一切 提交于 2019-12-28 07:05:07

问题


I keep reading posts which say that ActionListener methods must have the following signiture:

public void calledByActionListener(ActionEvent e) {
}

Invoked like so:

<p:commandButton value="Example" id="example" process="@this" ajax="false" 
    actionListener="#{exampleBean.calledByActionListener()}">

However I have a no-arg method like this which works:

public void calledByActionListener() {
}

Did something change?


回答1:


Yes, that's the new EL 2.2 feature of invoking methods with custom arguments. Basically, you're explicitly invoking an argumentless method. This construct is legit.

Note that this is not related to JSF2. EL 2.2 just happens to be part of Java EE 6 as well like JSF2. So it look like a new JSF2 feature. But it actually isn't. As evidence, JSF2 is backwards compatible with Java EE 5 which thus implies EL 2.1, but this construct doesn't work over there.

When not explicitly specifying any custom arguments in the method expression, JSF will as per the specification assume a default argument of ActionEvent in the actual method.



来源:https://stackoverflow.com/questions/14382466/jsf-actionlistener-tag-calls-method-which-doesnt-take-an-actionevent-paramete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!