• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp:useBean Doubt?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks man. I'm understanding it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic