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

前端 未结 6 2059
-上瘾入骨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: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}

提交回复
热议问题