• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean -- big doubt

 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys....could you please help me out with this....it's not mentioned in the errata list for HFSJ....The 12th bullet point on PAGE # 414 says --If you specify a "type" attribute in <jsp:useBean>, you can set properties in <jsp:setProperty> ONLY on properties of the "type", but NOT on properties that exist only in the actual "class" type.(In other words, polymorphism and normal Java type rules apply.)
I guess what they meant was THIS :

IF the classes are :
package foo;
public abstract class Person { private String name;
public void setName(String name) { this.name=name; }
public String getName() {return name;}
}
public class Employee extends Person{ private int empID;
public void setEmpID(int empID){ this.empID=empID; }
public int getEmpID() {return empID;}
}

THEN assuming the bean "testbean" doesn't exist is any of the scopes:
using
<jsp:useBean id="testbean" type="foo.Person" class="foo.Employee" >
<jsp:setProperty name="testbean" property="empID" value="656" />
</jsp:useBean>
would produce an error ....I think that's what they meant and it is justified as well because in Java you cannot do this ...
eg. foo.Person p=new Employee(); p.setEmpID(656)......


BUT...I using Tomcat 5.0.28 and, tell you what, it works fine when the above useBean code is used ....I'm dazed...please help

[ November 28, 2006: Message edited by: Sayak Banerjee ]
[ November 29, 2006: Message edited by: Sayak Banerjee ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i too am dazed !
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am tryin' myself but am unable to figure it out....Here's somethin' that might help...
The container is using the function below for the purpose of setting the property value which bends the polymorphism rules and I'm not sure how this works :-

org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("testbean"), "empID", "656", null, null, false);

I got it from the generated servlet code...Someone please help...Thanks in advance
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried for some hints in Spec but no use

Puzzled as to how this works right. Can someone explain?

Regards,
Mani
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes its working in my computer also.

I don't why?

It is really an interesting post.

I am waiting for the reply of either Bryan,Kathey or Bert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic