Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean "type" attribute!!!

 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose the JSP code is as following:



And suppose the class Person has one property name, and class Employee extends class Person and defines an additional property emID.

I reckon only name property will be set by the above JSP code because the type attribute of the <jsp:useBean> is foo.Person. Is this correct?
 
Rick Rangers
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure but I think that your assumption is right.

BTW: 98% SCJP is impressive!
 
Sandeep Krish
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per Java inheritance standards, if the name property is not a private variable, it sets the value for name property.

Please correct me if I am wrong
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I think that all available properties (which means properties having a proper setter method) of Employee will be set. Reflection is used in the case, so the bean's instance is considered as being an Employee.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tag will be trasalated as
in generated sevlet. empID won't be accessible with Person reference.

Anyone please confim me
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
empID won't be accessible with Person reference.

I don't agree.

Even though you've got "Person person = new Employee()", using reflection you can still access the empId. "person" is seen as a Person, but is still an Employee. person.getEmpId() is not being called directly. Reflection is used. The setter method of empId will be looked for, and called.
 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed.


with <jsp:useBean id="user" type="entity.Person" class="entity.Employee">
where Employee has property employeeNumber that Person does not:

In the generated servlet code: org.apache.jasper.runtime.JspRuntimeLibrary.handleSetPropertyExpression(_jspx_page_context.findAttribute("user"), "employeeNumber", "${requestScope.emp_num}", _jspx_page_context, null);

Even though user.getEmployeeNumber might not compile, the JSP get action works.

<jsp:getProperty name="user" property="employeeNumber"/>
[ March 06, 2007: Message edited by: Anupama Ponnapalli ]
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good work Anupama
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic