JSF - actionListener 标记调用不带 ActionEvent 参数的方法 [英] JSF - actionListener tag calls method which doesn't take an ActionEvent parameter

查看:27
本文介绍了JSF - actionListener 标记调用不带 ActionEvent 参数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读一些帖子,这些帖子说 ActionListener 方法必须具有以下签名:

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

public void calledByActionListener(ActionEvent e) {
}

像这样调用:

<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() {
}

有什么变化吗?

推荐答案

是的,这就是新的 EL 2.2 使用自定义参数调用方法的功能.基本上,您是显式调用无参数方法.这个构造是合法的.

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.

请注意,这与 JSF2 无关.EL 2.2 恰好是 Java EE 6 的一部分,就像 JSF2 一样.所以它看起来是一个新的 JSF2 特性.但实际上并非如此.作为证据,JSF2 向后兼容 Java EE 5,因此意味着 EL 2.1,但此构造在那里不起作用.

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.

当未在方法表达式中明确指定任何自定义参数时,JSF 将根据规范在实际方法中假定 ActionEvent 的默认参数.

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.

这篇关于JSF - actionListener 标记调用不带 ActionEvent 参数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆