File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:usebean

 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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:useBean>
<jsp:getProperty name="Emp" property="name"/>
<jsp:getProperty name="Emp" property="empId"/>


Here,
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

Regards
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a good question.
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...

JSP.5.2 <jsp:setProperty>
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 ]
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is it like ....the bean ojbect & its properties is considered ...at the time of setting them...and not the reference...

Regards
[ September 29, 2006: Message edited by: A Kumar ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic