• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

HFSJ - Doubt

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<blockquote>code:
<pre name="code" class="core">
<jsp:usebean id="person" type="foo.Employee" />
<jsp:getProperty name="person" property="name" />

foo.Person p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person",p);
</pre>
</blockquote>

Person => Abstract Class
Employee => Extends Person

Why the above code fails? Please explain elaborately.
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you paste the error you are getting ?

Following code should work perfectly:
<blockquote>code:
<pre name="code" class="core">
<jsp:useBean id="person" type="foo.Person" class="foo.Employee" />
<jsp:getProperty name="person" property="name" />
</pre>
</blockquote>
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shiaber

The reason your code fail is because you did not specify the scope.
If there is no scope attribute, the default scope is page.
But there is no "person" attribute in page scope.

Regards
Terence
 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wanted to know how usebean standard action behaves with only type attribute and also about page scope.

My queries are:

1) How usebean standard action behaves when type attribute alone is used?

Please explain with an example.

a) if type alone is used, will both the reference type and the object type will be the same as the value of type attribute ?

2) If we use page scope in usebean, will it search in all the scopes or just the page scope?



Kindly explain !!




Thanks.

[ July 17, 2008: Message edited by: Shiaber Shaam ]
[ July 17, 2008: Message edited by: Shiaber Shaam ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try:

1) How usebean standard action behaves when type attribute alone is used?
TypeClass x = (TypeClass)request.getAtttribute("attribute");

Please explain with an example.

a) if type alone is used, will both the reference type and the object type will be the same as the value of type attribute ?
If the type is used alone you must have an existing attribute, so the server will never instaciate this object, it means that doesn�t metter the object because the server will always do like in question one. If he tries to create a new one and error will occur.

2) If we use page scope in usebean, will it search in all the scopes or just the page scope?
just in the page scope



Kindly explain !!
 
reply
    Bookmark Topic Watch Topic
  • New Topic