I have a form with 2 input fields and i submit the form to a jsp which has this code
<jsp:useBean id="Emp" type="com.Person" class="com.Employee">
<jsp:setProperty name="Emp" property="name"/>
<jsp:setProperty name="Emp" property="empId"/>
<jsp:getProperty name="Emp" property="name"/>
<jsp:getProperty name="Emp" property="empId"/>
com.Person is abstract with a field name
com.Employee is concrete extending Person and has field empId
Now i am able to get the values of both the fields printed..
But my doubt is....
since Person is the reference type ..how is it able to set the value of empId that belongs to Employee..
the servlet code will be something like this...
Person Emp=new Employee();
Then how is it able to access the empId ...variable
I just tried this in Tomcat, and the answer is that it uses introspection to find the properties.
The generated servlet source....
And the reason introspection is used...
The jsp:setProperty action sets the values of properties in a bean.
The name attribute that denotes the bean must be defined before this
action appears. There are two variants of the jsp:setProperty action.
Both variants set the values of one or more properties in the bean
based on the type of the properties. The usual bean introspection
is done to discover what properties are present, and, for each, its
name, whether it is simple or indexed, its type, and the setter and
getter methods. Introspection also indicates if a given property type
has a PropertyEditor class.
[ September 29, 2006: Message edited by: Ben Souther ]