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