Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

jsp:useBean related doubt

 
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 ]
 
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 ]
 
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
 
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.
 
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
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
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