In my webapp, when I click on the login link, the Tomcat webserver throws the following exception:
exception
javax.servlet.ServletException: /aluno_jsf.xhtml
javax.el.ELException: /aluno_jsf.xhtml: Property 'logout' not found on type br.com.aluno.controller.LoginMB
This suggests that the #{loginMB.logout}
is been evaluated as a ValueExpression
instead of as a MethodExpression
.
That can for example happen if you're using <h:outputText value="#{loginMB.logout}" />
, or even when the x
namespace behind <x:someComponent action="#{loginMB.logout}" />
can't be resolved due to missing or incorrect XML namespace declaration or the JAR file containing the components not being included in the runtime classpath.
The cause is not visible in the code posted so far, but with my best guess you're not using Facelets templating properly. The code shows strange use case of <ui:decorate>
. Head to this answer to learn how to properly use template compositions: How to include another XHTML in XHTML using JSF 2.0 Facelets?
I would like to offer some reasons why you might get javax.el.ELException
on a EL Method reference in xhtml. Consider this a matter of reference, maybe others will continue to contribute.
xmlns
used in your <html>
tag.Example, if you are using Java EE 6, then this is wrong:
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
And should be instead
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
Note the use of sun.com instead of jcp. You should use jcp for Java EE 7 upward.
Note that similar issues exist for <persistence>
in persistence.xml, and <beans>
in beans.xml!
Research the documentation for the Tag Library, for the exact version you are using. You will have a few possibilities:
javax.el.MethodExpression
'. In that case it expects the supplied property to be of a different type and try to evaluate it as such. In case a Method is supplied it has to be with the ()
syntax, and the method will be executed only to retrieve the expected type.javax.el.ValueExpression
, in which case it does not even accept an Expression in EL syntax, and evaluation will happen immediately and only during rendering.For this particular question, we can refer to the PrimeFaces 3.4 Tag Documentation. It is unfortunate that the exact version used is not provided.
In this case, method references without ()
will by default interpreted as regular properties, and try to access getters/setters.
Logout isn't a property accessor, it's a method.
Try this: #{loginMB.logout()} instead
I had the same issue , and I solved it by removing comments that I added to my xhtml file
Solution found on this page