为什么我可以绑定<;f:actionListener>;如果它是';JSF不支持什么?

为什么我可以绑定<;f:actionListener>;如果它是';JSF不支持什么?,jsf,binding,actionlistener,el,methodexpression,Jsf,Binding,Actionlistener,El,Methodexpression,我使用的是Glassfish 3.1.2.2和JSF Mojarra 2.1.6 我有以下Facelets页面: <h:form> <h:commandLink value="link"> <f:actionListener binding="#{backingBean.someMethod(1)}"/> </h:commandLink> </h:form> 当我点击链接时,“信息:它被称为:1”出现在控制台中 绑定的

我使用的是Glassfish 3.1.2.2和JSF Mojarra 2.1.6

我有以下Facelets页面:

<h:form>
  <h:commandLink value="link">
    <f:actionListener binding="#{backingBean.someMethod(1)}"/>
  </h:commandLink>
</h:form>
当我点击链接时,“信息:它被称为:1”出现在控制台中

绑定的文档如下所示:

库:,(Jsf核心)

标签:actionListener

绑定

计算为实现javax.faces.event.ActionListener的对象的值绑定表达式。[我的重点]

此外,对的公认答案指出,
f:actionListener
不可能调用任意方法


如果不支持,为什么要调用支持bean方法?

这是新的EL 2.2特性的结果,该特性通过
{bean.method()}
语法调用值表达式中的方法,而不是通过
{bean.property}
语法仅引用属性(这应该是确切的类型
ActionListener
)。它在EL 2.1或更早版本中不起作用,如果删除参数和括号也不起作用。该文档是在EL 2.2不存在时编写的(与2006年5月相比,它实际上没有修改;EL 2.2于2009年12月推出)但是,我同意这一部分需要更新,因为它让初学者感到困惑

您找到的答案是基于文档的,但是回答者似乎没有意识到这一点,因为当
binding=“#{testController.nodeListener}”
失败时,
binding=“#{testController.nodeListener(event)}”
实际上起作用了。这只是没有给你机会传递
动作事件
。如果建议只使用
绑定=“#{testController.nodeListener()}”
并以其他方式获取事件信息,比如通过调用或甚至传递
{component},答案会更好
作为参数。当然,只有在您确实需要参与的情况下

<h:commandLink value="link">
    <f:actionListener binding="#{bean.someMethod(component)}"/>
</h:commandLink>
另见:
<h:commandLink value="link">
    <f:actionListener binding="#{bean.someMethod(component)}"/>
</h:commandLink>
public void someMethod(UIComponent component) {
    System.out.println("It was called on: " + component); // HtmlCommandLink
}