Two Laptop Bag*
The moose likes JSF and the fly likes Best Practices for JSF-Spring-Hibernate 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 "Best Practices for JSF-Spring-Hibernate " Watch "Best Practices for JSF-Spring-Hibernate " New topic

Best Practices for JSF-Spring-Hibernate

Bansilal Haudakari

Joined: Jun 28, 2004
Posts: 15
I have developed simple CRUD application using JSF, Facelets, Ajax4JSF, Spring & Hibernate based on Appfuse/Equinox framework. After making the application to work successfully i am wondering whether i have used the best practices. Here is an example

" Is it recommended to instantiate Model object in Backing bean"

To elaborate the statement .........

I have the following

UserForm is a JSF managed bean,
User is a hibernate mapped POJO, and
UserManager is manager class in Spring
------------------------ (Backing Bean)
public class UserForm {
public User user = new User();
public UserManager mgr;
// Getter & Setter methods for user & mgr
public String save() {
addMessage("user.saved", getUser().getFullName());

return "success";

I undertand the purpose of having UserManager defined in backing bean but wondering why do we need to have Model (i.e. User) defined in backing bean . Is this a best practice?

Is it recommended to populate model object with data in the backing bean and then call for business methods like mgr.saveUser(getUser()

I am wondering about perfomance issues i.e. making DB calls from backing bean getters or setters. DB calls can mean a performance hit, and JSF will call the getters and setters multiple times per page request (which means you'll be doing multiple DB calls).


Hung Tang
Ranch Hand

Joined: Feb 14, 2002
Posts: 148
I recommend that you check out JBoss Seam for JSF development. It uses Facelets, ajax4Jsf, JPA (Hibernate-based), etc. so you wouldn't need to do too much additional learning. Appfuse-JSF, IMO, is not a good JSF example that you should be looking at. It's overcomplicated, and it uses Spring (which is a good framework on its own) but it doesn't integrate well with JSF handling of stateful components. Check it out.
It is sorta covered in the JavaRanch Style Guide.
subject: Best Practices for JSF-Spring-Hibernate
Similar Threads
MVC Model and Domain Model
Issue in submitting the Form with Arraylist in Struts 1.1
Input text in each row of JSF datatable not getting updated while submitting
display collection without getters n setters
Resetting UIViewRoot