File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSF
Bookmark "Best Practices for JSF-Spring-Hibernate " Watch "Best Practices for JSF-Spring-Hibernate " New topic
Author

Best Practices for JSF-Spring-Hibernate

Bansilal Haudakari
Greenhorn

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
------------------------
UserForm.java (Backing Bean)
----------------------------
public class UserForm {
.........
.........
public User user = new User();
public UserManager mgr;
.............
.............
// Getter & Setter methods for user & mgr
....................
....................
//Persistence
public String save() {
mgr.saveUser(getUser());
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).



Regards

Bansi
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best Practices for JSF-Spring-Hibernate