This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes Persisting beans in a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Persisting beans in a database" Watch "Persisting beans in a database" New topic
Author

Persisting beans in a database

Rob Hyx
Greenhorn

Joined: Nov 12, 2008
Posts: 15
This is a general question about best practices for handling persisted data in JSF. My JSF page is going to have several fields that map to a managed bean. Upon a button click the fields of this bean are going to be persisted in a database. Is it better to use another bean with application scope to handle the JDBC code, or should I have a method in the bean itself to handle that? Similarly I'll need a method to retrieve the information upon a user request.

Thanks in advance!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

JSF UI Model objects (backing beans) should generally not also be ORM Persistence Model objects. That's because backing beans are normally singleton instances. JSF doesn't have any internal persistency or ORM locator functionality, so it's difficult to bind a non-unique ORM Model object (database table row) into the JSF UI.

What I normally do to get around that is make a distinct UI backing bean which contains a property named "data", which is the ORM instance that I'm dealing with. That allows the backing bean to interface with the ORM's finder and persistency functions (DAO, for example), plus it allows me a place to keep JSF's UI support properties and related methods.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
wood burning stoves
 
subject: Persisting beans in a database
 
Similar Threads
One View:two backing beans and a commandButton
result of the setter methods in EntityBeans
Entity beans BMP and CMP
What distinguishes a bean-managed persistent (BMP) enterprise bean from a container-m
Multiple DB access using multiple persistent units in same persistence.xml file