Forums Register Login

jsp:setProperty on sub-class allowed? It's working in Tomcat.

+Pie Number of slices to send: Send
Hello dear people of Javanranch! Thank you for such a great supporting website for all the Java people, I'll be using it a lot.

My question is this:

I'm preparing for the scwcd and ran into something strange. On page 414 of Head First Servlets & JSP, the bullet list it says (2nd from the bottom) that with useBean, you can only set properties of the parent type, but under Tomcat (5.5.26-5) it seems you can also set class-subtype properties.

jsp:useBean id="pageBean" type="myParentBean" class="myBean"

The MyBean extends MyParentBean, but I can still set properties of the myBean class

jsp:setProperty name="pageBean" property="salary" value="100"

While salary is a property of myBean and not myParentBean. The editor gives me a warning about this, but Tomcat simply executes it.

What's the official rule here? Is Tomcat right in executing 'correctly'? Thanks in advance for any help.
+Pie Number of slices to send: Send
I also did a similar test on tomcat 5.5.23 and got the same result.

I think the container (at least) Tomcat is treating the class as a java bean directly, not using the inhertance hierarchy. I didn't check the spec though.
+Pie Number of slices to send: Send
According to the spec, the container uses introspection to call the setter method. So it doesn't matter whether you're using the child or the parent. I remember adding this FAQ a long time ago
+Pie Number of slices to send: Send
 

Originally posted by Christophe Verre:
According to the spec, the container uses introspection to call the setter method. So it doesn't matter whether you're using the child or the parent. I remember adding this FAQ a long time ago



Thanks for replies. I assume that Tomcat did the correct thing and that treatment of de type and class aren't as strict as mentioned in the book.
Come have lunch with me Arthur. Adventure will follow. This tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 612 times.
Similar Threads
jstl calling a method on a class
a big doubt on jsp:useBean
jsp:setProperty
Multiple submit buttons with JavaBeans
how do I set a java bean's property which is neither a String nor primitive in JSP?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:20:39.