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 Question

 
A Garg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a doubt regarding the <jsp:useBean> action in JSP 2.0. Let's have following two classes and JSP code snippets.

================================================
package foo;

public abstract class Person {
private String name = null;

// setter and getter methods
public void setName(...)
public String getName() ....
}


package foo;

public class Employee extends Person {
private int empId;

// setter and getter methods
public void setEmpId(...)...
public int getEmpId() ...
}
================================================

Scenario 1:
--------------------------------------------------------------------
<!-- HTML code goes here-->
<jsp:useBean id="person" type="foo.Person" class="foo.Employee" />

Name is <jsp:getProperty name="person" property="name" />

<%-- empid should NOT work because empId property is defined in subclass--%>
EMP ID is <jsp:getProperty name="person" property="empId" />
--------------------------------------------------------------------

Scenario 2:

--------------------------------------------------------------------
<!-- HTML code goes here-->
<jsp:useBean id="person" type="foo.Employee" class="foo.Employee" />

Name is <jsp:getProperty name="person" property="name" />

<%-- empid should work because type is foo.Employee --%>
EMP ID is <jsp:getProperty name="person" property="empId" />
--------------------------------------------------------------------

My doubt is Scenario 1 should throw an runtime error because bean class type is foo.Person and getEmpId() method should not be acessible to it. But this
works in Tomcat 5.5.7 (JSP 2.0) while it throws (as per my understanding) error in Weblogic 8.1 (JSP 1.2 complient)

Can somebody put some light on this and what is the correct behaviour. I have read JSP 2.0 spec but coudn't find anything specific to this issue.

Thanks,
Anil
 
Rodrigo W Bonatto
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Kathy has already given a explanation for this.

http://www.coderanch.com/t/168204/java-Web-Component-SCWCD/certification/jsp-useBean-setProperty-HFS-query

Regards,

Rodrigo
 
A Garg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rodrigo for providing link....

Cheers
Anil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic