Calling the Expression method without parameters in JSF 2.0

I am trying to call a parameterless method from JSF 2.0 bot on

#{myBean.foo()} 

(without any surrounding tag).

According to Burns / Schalk: full link: JSF 2.0, which is possible (p. 126, # {userBean.pullValuesFromFlash ()}).

However, the structure accepts the expression as an expression of value and therefore considers foo to be a bean property. In JBOSS 7.0.1 (and 6 too) I get

"Class" ... "does not have the property" foo ""

error message.

+4
source share
3 answers

Judging by this answer on the JBoss forum , method expressions should only be used in attributes that support them.

Stan Silvert wrote:

It seems to me that this works as expected. This has nothing to do with the lack of arguments. Your expression, #{elManagedBean.hello()} treated as a ValueExpression expression. If you change your method to getHello() , then it will work. the question is, should it be considered as ValueExpression or MethodExpression ? For example, if you had the same expression in the attribute, the action would be considered as MethodExpression .

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

You put the expression in the middle of the Facelets page, not as an attribute value. As far as I know, this will always be considered as ValueExpression . I do not see how this will work in Glassfish. It is possible that there is code that tries it as a ValueExpression , and then tries to use it as a MethodExpression if it fails. However, I think this will contradict the EL spec. In other words, I am surprised that Glassfish will work.

+2
source

McDowell responded to the cause of the problem: inline expressions are treated as value expressions, not method expressions.

As for how to achieve the functional requirement anyway, use <f:event> .

 <f:event type="preRenderView" listener="#{myBean.foo}" /> 

This will invoke the method just before the rendering response.

+2
source

It depends on the version of EL you are using in the servlet container. When using Tomcat 6, EL 2.1 is enabled, and it does not support '()' like MethodExpression if the expression is in the middle of the Facelets page. Tomcat 7, which includes EL 2.2, supports these and even improved functions as the ability to pass parameters to a method expression:

So you do this:

 <h:outputText value="#{object.test(10)}" ></h:outputText> 

And get the parameter in a bean (additional conversion and verification may be required):

 public String test(MyObject o) { ... return value; } 

References: http://tomcat.apache.org/whichversion.html Using EL 2.2 with Tomcat 6.0.24

0
source

All Articles