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

HFSJ - Doubt

 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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.
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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>
 
Terence Thant Zin Oo
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Rodrigo Vieira
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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 !!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic