Suggest a design pattern for an application using JSF, EJB 3.0

I have created a demo application. Using JSF and EJB 3.0 (stateless stateless session bean and JPA) my persistence provider is Hibernate 4 and the database is Apache Derby.

My class flow, next sequential flow,

ManagedBean invokes a stateless session bean, in this case we have JPA calls,

please follow the code, JSF managed the bean,

public class StudentMgBean implements Serializable{
     private static final long serialVersionUID = 109117543434170143L;
     private StudentService studentService; 
     public void init(){
           this.totalStudentInDB = studentService.getMaxStudent();


My EJB interface,

public interface StudentService {
    List<StudentVO> fetchStudentListOrderByStudentId(boolean flag);

    List<StudentVO> fetchStudentListOrderByStudentName(boolean flag);

    void saveStudentEntity(StudentEntity studentEntity,Integer deptId) throws Exception;

    List<DeptEntity> fetchAllDept();

    List<StudentVO> fetchStudentByDept(Integer deptId);

    void saveAllStudents(List<StudentVO> students) throws Exception;

    void deleteAllStudents(List<StudentVO> students) throws Exception;

    List<StudentVO> fetchStudentListPerPage(Integer minRow,Integer maxRow) throws Exception;

    Integer getMaxStudent() throws Exception;


My EJB idle session bean,

public class StudentServiceBean implements StudentService{
    private EntityManager entityMgr;

    private SessionContext sessionContext;

    private DeptService deptService;

    public List<StudentVO> fetchStudentListOrderByStudentId(boolean flag){

    public void saveStudentEntity(StudentEntity studentEntity,Integer deptId) throws Exception{



In StudentServiceBean, I have injected EntityManager, so I directly perform JPA operation in methods written in this session bean.

There is no question of mine, can I use any design pattern in this thread, can I go to a separate DAO layer, since I am using EJB 3.0, I do not need to use the ServiceLocator pattern, but than any other pattern I can use to separate logic Bussiness with JPA call,

One more thing, In a JSF managed bean, I have properties and methods for setting it that map to JSP components in EL like this Value = {stMgBean.studentList}

but in the same managed bean I also have a method that will be called by invoking the action command from JSF, should this method be written in a separate managed bean?

Please suggest a design template that can be used for projects with JSF 2.0, EJB 3.0 and JPA

waiting for an answer


source to share

1 answer

You can split the JSF layer using the following concepts:

  • Place all the data to be shared with the java side and the view into specific managed beans called Models. You can now manage the amount of data independently of the scope of the rest of the managed beans.
  • Use a command template that delegates all actions that will modify the model for commands. Commands can call the EJB layer or simply update the models without going to the next level.
  • Store in the managed beans only the logic needed to initialize JSF beans in views or control their behavior, a reference to the model, and a reference to a delegate that will provide the command to run.


All Articles