Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

jsp:useBean -- big doubt

 
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 ]
 
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
 
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
 
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
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic