JSF - actionListener tag calls method which doesn&

2019-01-15 20:26发布

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条回答
forever°为你锁心
2楼-- · 2019-01-15 20:45

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.

查看更多
登录 后发表回答