• 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

Are javabeans of any use?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am new to jsp and javabeans so i'm trying to decide where its best to use beans. AFAIK beans are held in server ram and thus therefore should not be too resource intensive. Bearing this in mind i see no use for them other than maintaining state which can be maintained else where using implicit objects. So my question is, is it a best practice to use beans and if so for what?
Thanks
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With respect to JSP, JavaBeans are useful for maintaining state and for representing the information (the model) of your web application. You can use them to wrap up reusable functionality, although custom tags (also known as JSP tag extensions) are the preferred solution.
For a more detailed look at what JavaBeans and custom tags are useful for, check out Chapter 8 (Tag Patterns) of Professional JSP Tag Libraries that is available to download for free.
Hope that's useful
Simon
[ September 26, 2002: Message edited by: Simon Brown ]
 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is what i dont understand. I would have thought for reusable functionality the fact that beans stay in memory would mean lots of additional use of server ram for a site that was built in this way. Is this acceptable (i.e. does not harm performance that much)?
thanks
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Common practice is to have a Servlet place the bean in an object available to the JSP Page (Request, Session, Context). Usually the Request is used. Once the page is rendered, the Request goes out of scope. Once it goes out of score, all beans placed in it go out of scope. The beans will not stay in memory for long.
The alternative is to create a bean pool type object that recycles the beans.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main reason for using JavaBeans or any other helper class is to get the Java code out of JSP. The theory being that this helps separate content generation from presentation and makes the whole package more maintainable.
After you have spent countless hours trying to debug a huge JSP that mixes code and HTML you may come to appreciate JavaBeans.
Personally I like the idea of writing a separate test application to thoroughly wring out a JavaBean before using it in JSP.
Bill
 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thanks for the replies. I think its starting to click. Am i right in saying tags exist mainly to access these beans (so that you dont have scriplets and html intermingled). And if so what advantages does using beans have over regular classes ? I think because so many things can be done so many ways the hardest thing to grasp is what to use where and why (i.e what tradeoffs have to be made etc.) in anysight into this or pointers to resources would be gratefully helpful!
Thanks
Kola
 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry one other thing i wanted to ask, why do servlets place the bean in the request scope why not just do it in the page, is this again to avoid having html and java intermingled?
thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic