JSF 2.0 中不带参数的 MethodExpression 调用
我试图通过
#{myBean.foo()}
(没有任何周围的标签)从 JSF 2.0 Facelet 调用无参数方法。
根据 Burns/Schalk:完整参考:JSF 2.0,这是可能的(第 126 页,#{userBean.pullValuesFromFlash( )})。
然而,框架将表达式视为值表达式,因此认为 foo 应该是 bean 属性。 在 JBOSS 7.0.1(以及 6)上,我收到
“类 '...' 没有属性 'foo'”
错误消息。
I'm trying to invoke a parameterless method from a JSF 2.0 facelet by
#{myBean.foo()}
(without any surrounding tag).
According to Burns/Schalk: The Complete Reference: JSF 2.0 that's possible (page 126, #{userBean.pullValuesFromFlash( )}).
However the framework takes the expression to be a value expression and thus thinks that foo should be a bean property.
On JBOSS 7.0.1 (and 6, too) I get a
"The class '...' does not have the property 'foo'"
error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 JBoss 论坛上的此回复来看,方法表达式只能在支持的属性中使用他们。
Judging by this response on the JBoss forum, method expressions must only be used in attributes that support them.
McDowell 已经回答了问题的原因:内联表达式被视为值表达式,而不是方法表达式。
至于如何实现功能需求,请使用
。这将在渲染响应之前调用该方法。
McDowell has answered the cause of the problem: inline expressions are treated as value expressions, not as method expressions.
As to how to achieve the functional requirement anyway, use
<f:event>
.This will invoke the method right before render response.
这取决于您在 servlet 容器上使用的 EL 版本。如果使用 Tomcat 6,则包含 EL 2.1,并且如果表达式位于 Facelets 页面的中间,则不支持“()”作为 MethodExpression。 Tomcat 7(包括 EL 2.2)确实支持此功能,甚至增强了功能,能够将参数传递给方法表达式:
因此您可以这样做:
并在 bean 中接收参数(可能需要额外的转换和验证):
参考:
http://tomcat.apache.org/whichversion.html
将 EL 2.2 与 Tomcat 6.0.24 结合使用
This depends on the EL version you are using on your servlet container. If using Tomcat 6, EL 2.1 is included and this does not support '()' as MethodExpression if the expression is in the middle of the Facelets page. Tomcat 7, which includes EL 2.2 does support this and even enhanced features as being able to pass parameters to the method expression:
So you do this:
And receive the parameter in your bean (extra conversion and validation might be needed):
References:
http://tomcat.apache.org/whichversion.html
Using EL 2.2 with Tomcat 6.0.24