• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

jsp:useBean "type" attribute!!!  RSS feed

 
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?
 
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!
 
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
 
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.
 
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.
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!