gpt4 book ai didi

jsf - JSF 2.0 中不带参数的 MethodExpression 调用

转载 作者:行者123 更新时间:2023-12-01 01:26:41 24 4
gpt4 key购买 nike

我正在尝试从 JSF 2.0 facelet 调用无参数方法

#{myBean.foo()}

(没有任何周围的标签)。

根据 Burns/Schalk: The Complete Reference: JSF 2.0,这是可能的(第 126 页,#{userBean.pullValuesFromFlash( )})。

然而,框架将表达式视为一个值表达式,因此认为 foo 应该是一个 bean 属性。
在 JBOSS 7.0.1(和 6)上,我得到一个

“类 '...' 没有属性 'foo'”

错误信息。

最佳答案

this response on the JBoss forum 判断, 方法表达式只能用在支持它们的属性中。

Stan Silvert wrote:

It looks to me like this is working as expected. This has nothing to do with a lack of arguments. Your expression, #{elManagedBean.hello()} is being treated as a ValueExpression. If you changed your method to getHello() then it would work. The question is, should it be treated as a ValueExpression or a MethodExpression? For instance, if you had the same expression in an action attribute it would be treated as a MethodExpression.

<h:commandButton value="Hello" action="#{elManagedBean.hello()}" 
id="submit_button"/>

You have put the expression in the middle of the Facelets page and not as the value of an attribute. As far as I know, this will always be treated as a ValueExpression. I don't see how this would work in Glassfish. It's possible that there is some code that tries it out as a ValueExpression and then tries it as a MethodExpression if it fails. However, I think that would go against the EL spec. In other words, I'm surprised that this would work on Glassfish.

关于jsf - JSF 2.0 中不带参数的 MethodExpression 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7345417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com