• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

jsp:useBean -- big doubt

 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i too am dazed !
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
eat bricks! HA! And here's another one! And a tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic