Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean tag query.

 
Vinayak Jallapelli
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

While reading Head First Servlets and JSP book (2nd Edition), I came across topic (on page 362, chapter 8) explaining how we can set the values from HTML form directly to Java Beans using "jsp:useBean" tag.
In the example, following classes are used:



The sample HTML form is as below. This form contains parameters whose name are equivalent to properties of above Java classes.



As per the book, we can use the following tag to set the form values straight to the bean:



My question is, in the above useBean tag, how does the container sets the EmpID attribute of the bean, since the instance that container creates is of type "foo.Person"? "foo.Person" has no visibility of empID property of its child class "foo.Employee".

Regards,
Vinayak
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinayak Jallapelli wrote:


will it compile? probably typing error
Vinayak Jallapelli wrote:

My question is, in the above useBean tag, how does the container sets the EmpID attribute of the bean, since the instance that container creates is of type "foo.Person"? "foo.Person" has no visibility of empID property of its child class "foo.Employee".

here, first container create an instance of foo.Employee and then sets its value , then this object is assigned to the reference to foo.Person[which is a super class of foo.Employee]

<edit>
and while displaying empId , container will type cast to subclass then invoke the attribute like

</edit>

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic