• Post Reply Bookmark Topic Watch Topic
  • New Topic

javabeans for business logic or to maintain state?

 
k Oyedeji
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • 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!!
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!