javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean

前端 未结 6 2039
-上瘾入骨i
-上瘾入骨i 2020-11-21 23:37

I have results from

Query query = session.createQuery(\"From Pool as p left join fetch p.poolQuestion as s\");

query and I would like to di

相关标签:
6条回答
  • 2020-11-22 00:07

    EL interprets ${class.name} as described - the name becomes getName() on the assumption you are using explicit or implicit methods of generating getter/setters

    You can override this behavior by explicitly identifying the name as a function: ${class.name()} This calls the function name() directly without modification.

    0 讨论(0)
  • 2020-11-22 00:07

    I was facing the similar type of issue: Code Snippet :

    <c:forEach items="${orderList}" var="xx"> ${xx.id} <br>
    </c:forEach>

    There was a space after orderlist like this : "${orderList} " because of which the xx variable was getting coverted into String and was not able to call xx.id.

    So make sure about space. They play crucial role sometimes. :p

    0 讨论(0)
  • 2020-11-22 00:08

    javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean

    This literally means that the mentioned class com.example.Bean doesn't have a public (non-static!) getter method for the mentioned property foo. Note that the field itself is irrelevant here!

    The public getter method name must start with get, followed by the property name which is capitalized at only the first letter of the property name as in Foo.

    public Foo getFoo() {
        return foo;
    }
    

    You thus need to make sure that there is a getter method matching exactly the property name, and that the method is public (non-static) and that the method does not take any arguments and that it returns non-void. If you have one and it still doesn't work, then chances are that you were busy editing code forth and back without firmly cleaning the build, rebuilding the code and redeploying/restarting the application. You need to make sure that you have done so.

    For boolean (not Boolean!) properties, the getter method name must start with is instead of get.

    public boolean isFoo() {
        return foo;
    }
    

    Regardless of the type, the presence of the foo field itself is thus not relevant. It can have a different name, or be completely absent, or even be static. All of below should still be accessible by ${bean.foo}.

    public Foo getFoo() {
        return bar;
    }
    
    public Foo getFoo() {
        return new Foo("foo");
    }
    
    public Foo getFoo() {
        return FOO_CONSTANT;
    }
    

    You see, the field is not what counts, but the getter method itself. Note that the property name itself should not be capitalized in EL. In other words, ${bean.Foo} won't ever work, it should be ${bean.foo}.

    See also:

    • javax.el.PropertyNotFoundException: Property 'foo' not readable on type java.lang.Boolean
    • How does Java expression language resolve boolean attributes? (in JSF 1.2)
    • Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
    • Outcommented Facelets code still invokes EL expressions like #{bean.action()} and causes javax.el.PropertyNotFoundException on #{bean.action}
    0 讨论(0)
  • 2020-11-22 00:08

    Check the items in forEach

        <c:forEach items="${pools}" var="pool"> 
    
            ${pool.name}
    
        </c:forEach>
    

    Some times items="${pools}" has an extra space or it acts like string, retyping it should solve the issue.

    0 讨论(0)
  • 2020-11-22 00:15

    I get the same error on my JSP and the bad rated answer was correct

    I had the folowing line:

    <c:forEach var="agent" items=" ${userList}" varStatus="rowCounter">

    and get the folowing error:

    javax.el.PropertyNotFoundException: Property 'agent' not found on type java.lang.String

    deleting the space before ${userList} solved my problem

    If some have the same problem, he will find quickly this post and does not waste 3 days in googeling to find help.

    0 讨论(0)
  • 2020-11-22 00:33

    I believe the id accessors don't match the bean naming conventions and that's why the exception is thrown. They should be as follows:

    public Integer getId() { return id; }    
    public void setId(Integer i){ id= i; }
    
    0 讨论(0)
提交回复
热议问题