aspose file tools
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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Persisting beans in a database" Watch "Persisting beans in a database" New topic

Persisting beans in a database

Rob Hyx

Joined: Nov 12, 2008
Posts: 18
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: 16540

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.
I agree. Here's the link:
subject: Persisting beans in a database