aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes <jsp:useBean> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "<jsp:useBean>" Watch "<jsp:useBean>" New topic
Author

<jsp:useBean>

Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180


code inside jsp:useBean is conditional means .. what?? I didn;t understand this..
This is in chapter 8 and page no: 352 inHFSJ
Please clarify/....
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

If there is no person bean in request scope than the code inside <jsp:useBean tag executed(<jsp:setProperty) and it first create a new person bean in the request scope then set its name property to Fred

However on the other hand, if there is a person bean in the request scope ><jsp:setProperty is not
executed!
So this means ><jsp:setProperty works conditionally based on person bean existence in the scope which you defined in <jsp:userBean tag.

To conclude, if you use a body in <jsp:useBean than the bean existence is important for the behaivor of tag inside <jsp:useBean.


blog: http://tunatore.wordpress.com
SCJP 6.0 + SCWCD 1.5
Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180
Ok if I want to see this practically...
How can we say that bean object is in request scope or it is not in request scope........
Please explain???


Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

You can put it in request scope by an servlet

yourpage.jsp which cotains



Below code should be set in a servlet doGet() or doPost() method and should be redirected to yourpage.jsp



You can call servlet with a html link in a regular html page



There can be another solutions also The above code works for the bean which exists.
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
hii,

one small doubt.. now if i set the person bean in request scope.. setProperty will not work right?? when i use getProperty it will result in null is it??

please confirm.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
No .. that is not the way it works...

If person bean dosen't exits then only <jsp:setProperty> tag executes and repleces the existing property. But by the example mention above it sets the person bean in the request scope, so <jsp:setProperty> not executes..

But if you use <jsp:getProperty> which is not inside the <jsp:useBean> tag (not based on condition) it executes and get you the value of the mention property, in this case value of name property, if it got some value. means existing value of the name property.

Hope this help you


Thanks <br />Poonam Agarwal SCWCD 86%
sravanthi pulukuri
Ranch Hand

Joined: Mar 15, 2007
Posts: 125
hi,
yes i got it.. based on the above example,see it has bean object set in request scope so setProperty doesnt not execute ,getProerty will give the value of name.. in this case it has no value it will be null.

correct me if iam wrong.
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Yes !!! you got the point

best of luck AND keep posting
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: <jsp:useBean>