ManagedBean property not found

前端 未结 4 1811
夕颜
夕颜 2021-01-03 12:58

In my webapp, when I click on the login link, the Tomcat webserver throws the following exception:

exception
javax.servlet.ServletException: /aluno_jsf.xhtml         


        
相关标签:
4条回答
  • 2021-01-03 13:40

    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?

    0 讨论(0)
  • 2021-01-03 13:50

    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.

    Mismatch of Java EE versions

    • The Java EE version running on your AppServer. This should be part of your AppServer documentation, or if you customized it (like building your own on top of tomcat), you should know.
    • The tag libraries used, which can be identified with the 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!

    Tag Attribute that does not support MethodExpression

    Research the documentation for the Tag Library, for the exact version you are using. You will have a few possibilities:

    1. The tag attribute is not included in the specification. This can be possibly because it was added only in a later version of the tag library. In that case, the code will assume that it is a regular property, and will be evaluated during the rendering phase as a regular property (looking for a getter). This is also the reason behind the failure in case of Java EE version mismatch.
    2. The tag attribute is documented, but it is not specified that it 'must evaluate to 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.
    3. the tag attribute is documented, but it is not documented as of 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.

    EL Implementation does not support Method References

    In this case, method references without () will by default interpreted as regular properties, and try to access getters/setters.

    0 讨论(0)
  • 2021-01-03 13:52

    Logout isn't a property accessor, it's a method.

    Try this: #{loginMB.logout()} instead

    0 讨论(0)
  • 2021-01-03 13:52

    I had the same issue , and I solved it by removing comments that I added to my xhtml file

    Solution found on this page

    0 讨论(0)
提交回复
热议问题