带有EL 2.2的JSF 2.x为何允许MethodExpression代替ValueExpression? [英] How come JSF 2.x with EL 2.2 allows MethodExpression in place for ValueExpression?

查看:79
本文介绍了带有EL 2.2的JSF 2.x为何允许MethodExpression代替ValueExpression?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到几个问题,询问如何将参数传递给JSF方法.使用EL2.2和Servlet 3.0,它使用户可以将参数传递到方法调用中. 一个示例:如何将参数从渲染的方法传递给方法h:outputText?问题是:在JSF 2.x中,每个标记属性都应该采用ValueExpression或MethodExpression.在链接的示例中,"rendered"应该仅采用ValueExpression.但是我确实看到,如果我们将()清楚地表明它是方法调用而不是属性,它仍然可以与MethodExpression一起使用.这是JSF 2.x规范搞砸了吗,还是我缺少了什么?

I am seeing several questions asking how to pass parameters to JSF methods. With EL2.2 and servlet 3.0, it enables user to pass parameters into a method call. One example: How to pass an argument to method from rendered h:outputText? The question is: In JSF 2.x, each tag attribute is supposed to take either ValueExpression or MethodExpression. In the linked example, "rendered" is supposed to only take ValueExpression. However I do see it still works with MethodExpression if we put () to make it clear it is a method call instead of a property. Is this something the JSF 2.x spec just messed up or am I missing something?

推荐答案

在值表达式中使用新的EL 2.2带有参数的调用语法不会自动使它成为方法表达式之类的东西.它仍然是一个价值表达.值表达式使用给定EL表达式的返回值作为值.方法表达式在与组件相关联的动作事件上调用给定的EL表达式.

Using the new EL 2.2 invoking-methods-with-arguments syntax in a value expression doesn't automagically make it a method expression or something. It's still a value expression. A value expression uses the returned value of the given EL expression as a value. A method expression invokes the given EL expression upon an action event associated with the component.

EL表达式本身是调用属性getter方法还是带参数的任意方法,实际上对于整个EL表达式的处理方式无关紧要.

Whether the EL expression at its own invokes a property getter method or an arbitrary method with arguments really doesn't matter as to how the EL expression at the whole is treated.

这篇关于带有EL 2.2的JSF 2.x为何允许MethodExpression代替ValueExpression?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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