Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean related doubt

 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ(pg 416),they have this in one of the "BE he Container" sections:


They say this would fail:

Reason for failure:


But,I was wondering,so what would work,would this be the right solution.Would this work:


thanks in advance.
[ June 27, 2006: Message edited by: Jas Oberai ]
 
Jan Kostelansky
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason, why it does not work, is jsp:useBean standard action's default scope is page.
It is impossible to set attribute into page scope in servlet.
If appropriate scope attribute is added into jsp:useBean, the example should work.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool....thanks Jan
[ June 27, 2006: Message edited by: Jas Oberai ]
 
sarang bharambe
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey friends,
I am confused about all this discussion.


Actually the handwritten note on the page 416 in HFSJ says,
the tag body executes ONLY if a new bean is created....

But when is the new bean is created??
Is it when,<jsp:useBean> tag is encountered or anytime else?

Can anyone throw light on this?

Thanks in advance

Sarang bharambe
 
Raghusham Sankargal
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

According to the question I do not think the tag will work.even if you changed the scope to request in the tag. This is because the new attribute is not created if you are not using class attribute. As we have only type then and when ever only type attribute is used then we should ensure that the bean is already present.
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you specify type without a class then the bean name must exist in the specified scope,if no scope is specified the default is page.

<jsp:useBean id='person' type='foo.Employee'>
<jsp:setProperty name='person' property='name' value='Fred'/>
</jsp:useBean>

In this case type is used...so the bean person must exist in the page scope...otherwise you wil get an exception.


Corect me if i am wrong
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception will not arise If you add scope="request" .(hope the bean 'person' is in the request scope).
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just need to add the request scope and it works fine i.e.:

<jsp:useBean id='person' type='foo.Employee' scope="request">
<jsp:setProperty name='person' property='name' value='Fred'/>
</jsp:useBean>


Because in the servlet,you are setting the bean in the request scope.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic