Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best Practices for JSF-Spring-Hibernate

 
Bansilal Haudakari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic