Reputation: 195
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.
Upvotes: 4
Views: 1089
Reputation: 782
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:
<h:outputText value="#{object.test(10)}" ></h:outputText>
And receive the parameter in your bean (extra conversion and validation might be needed):
public String test(MyObject o)
{
...
return value;
}
References: http://tomcat.apache.org/whichversion.html Using EL 2.2 with Tomcat 6.0.24
Upvotes: 0
Reputation: 1108557
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>
.
<f:event type="preRenderView" listener="#{myBean.foo}" />
This will invoke the method right before render response.
Upvotes: 2
Reputation: 108859
Judging by this response on the JBoss forum, method expressions must only be used in attributes that support them.
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 togetHello()
then it would work. The question is, should it be treated as aValueExpression
or aMethodExpression
? For instance, if you had the same expression in an action attribute it would be treated as aMethodExpression
.<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 aValueExpression
and then tries it as aMethodExpression
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.
Upvotes: 2