javax.el.PropertyNotFoundException in a JSP page
Asked Answered
J

1

8

I am getting an error in JSP and I cannot figure out what is causing it. I have included all of the appropriate libraries and I've made sure to follow bean convention on uppercase/lowercase. Here's the relevant code in the JSP:

<c:forEach items="${relevantData}" var="entry">
     <p>${entry.price}</p>
</c:forEach>

The relevantData was a List<MyData>. For the purposes of this question it is sufficent to say MyData is a class that contains a Double named price (with a Getter and Setter following the bean convention). When I try to load this page I receive the following error in the server logs (Tomcat 7.0.22):

javax.el.PropertyNotFoundException: 
Property 'price' not readable on type java.lang.Double

Why am I getting this error and how do I fix it?

Jala answered 19/6, 2012 at 21:55 Comment(2)
accessor methods are public, is MyData inner class ?Frustrate
The accessor methods are all public. The class itself was not public.Jala
J
21

The problem was actually caused by the visibility of the MyData class. I had auto-generated the MyData class in Netbeans but I did not notice that there was no keyword public in front of the class name. This meant that by the time it got to the JSP there was no way for it to read the properties in MyData.

I changed the type to public and the problem was solved.

Jala answered 19/6, 2012 at 21:55 Comment(4)
I run into the exact same problem. moved type to new file, but forget to add public... thanks!Chub
doh, I should have been able to figure this one out ! Thanks for this post!Emsmus
This issue also arised after I used UCDectector to delete unnecessary code in eclipse. As the program was unable to interpret the JSTL-code, it suggested that I changed the modifier of the class to "default", and I did. Thanks for the help to locate my problem.Chile
Thanks a lot, it took me the whole day checking getter name; but I was blind to check the class visibility :(Chewning

© 2022 - 2024 — McMap. All rights reserved.