This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes jsp:useBean tag query. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:useBean tag query." Watch "jsp:useBean tag query." New topic
Author

jsp:useBean tag query.

Vinayak Jallapelli
Greenhorn

Joined: Feb 27, 2008
Posts: 11
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


Best Regards,<br />Vinayak Jallapelli
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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>

 
Consider Paul's rocket mass heater.
 
subject: jsp:useBean tag query.
 
Similar Threads
HFS page 361
Concrete class problem in EL
Error on basic jsp...
jsp:useBean doubt
page 360 if property="*"