• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

javabeans for business logic or to maintain state?

 
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 a bit confused as to whether javabeans are more suited for business logic or to maintain state for web applications.
Any pointers would be appreciated.
Thanks
 
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
As I see it, the main virtue of the Java Bean conventions for JSP are the ease of getting and setting variables and holding them over the duration of a session.
People do use them for business logic, particularly if it is simple database access, etc. but you don't want something that is going to be held in a session to be too big. Also be very careful not to hold system resources (such as database connections) in a bean that is going to last longer than a request.
Bill
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pigsie
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javabeans are not designed for one the other specifically. I use javabeans for business logic so as to not duplicate code (or more often than not refactor it out from other code when I realized its going to be useful in more than one context or that in some way isolating the code would be helpful)
and java beans are useful for holding session information, the important thing to remember is not to mix the two together too much both to limit the size of data stored in session, but also because the two dont belong together - you dont want to fix code that includes user information in order to maintain some business code - its akward, can cause problems with serialization, and therefore is not good practice.
 
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
Dave
Thanks for the heads up I dont think i came across the naming policy when registering.
Thanks for the replies. One thing which is not clear to me: Are beans automatically tied to a particular session or do they have to be programatically stored in the session scope?
Thanks guys
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your beans can have page, request, session, or application scope. Which of these scopes you use will depend on your needs. The default scope if you don't specify any is "page".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic