aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean Doubt? 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 Doubt?" Watch "jsp:useBean Doubt?" New topic
Author

jsp:useBean Doubt?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Guys,

when we use the <jsp:useBean> tag with a body, the value for the beans property will be set only if the bean does not have a value already set. So, setProperty is like giving a default value to the bean, if it is not set. Am I right?? Is this the real world use of the setProperty??

Help needed!


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

One more doubt to the useBean property is that if I use only the type instead of the class, then the bean must already exist. So does that mean that if I use only type without class, then I can use setProperty provided that the bean is not there already??
Arunabh Dash
Greenhorn

Joined: Apr 05, 2006
Posts: 20
hi ,
I don't know i got you completly or not, still trying to clear it .....
<jsp:useBean> have two forms .

1)
<jsp:useBean id="user" class="mypack.User"/>
<jsp:setProperty name="user" property="name"/>
2)
<jsp:useBean id="user" class="mypack.User">
<jsp:setProperty name="user" property="name"/>
<jsp:useBean/>

In the 1st case if the bean object is not there container will create an bean object and will set it's name property .
If the bean object is there then also the container will set it's name property .

But in second case if the bean object is not there container will create an bean object and will set it's name property .
But if the bean object is there then body of the <jsp:useBean> is not executed . So now the bean will have the previously set values .

when we use the <jsp:useBean> tag with a body, the value for the beans property will be set only if the bean does not have a value already set.

So this is not always true as i explained previously .
So, setProperty is like giving a default value to the bean, if it is not set. Am I right??

You can said that . Thing is that bean specification says that in side bean constructor we shouldn't do anything (i mean setting any property ). Bean should have diferent public setter method for setting it's property .
Thus for setting the bean property we are invoking <jsp:setBean > tag .

If you are still not clear reply back .....
with regards
Arunabh
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Thanks man. I'm understanding it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean Doubt?