• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Raoul Kalk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
liao Yang
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Raoul Kalk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic