2 Replies Latest reply on Mar 24, 2009 1:39 PM by nschweig

    Project EJB and JSF designquestion - where to implement whic

    nschweig

      I am developing an application with JSF and EJB 3.0.
      Now I have got a question where I should implement methods that manipulate my objects.

      Example1: The EJB SessioBean only implements methods to get data from the database and to persist or merge objects:

      EJB SessionBean courseHandler

      public void createCourse(Course course){
       em.persist(course);
      }


      The managedBean courseBean manipulates the object:
      managedBean JSF courseBean

      public void joinCourse(){
       currentUser = userHandler.getCmtUserByUserName(getRemoteUserName());
       currentCourse.getParticipants().add(currentUser);
       currentUser.getCourses().add(currentCourse);
       courseHandler.updateCourse(currentCourse);
       CustomMessage.createMessage("course_joined");
      }



      Or should example 2 be the better version:

      The EJB SessionBean courseHandler manipulates the object and persists/merges it:

      public void joinCourse(CmtUser user, Course course){
       course.getParticipants().add(user);
       user.getCourses().add(course);
       em.merge(course);
      }


      managedBean JSF courseBean

      public void joinCourse(){
       currentUser = userHandler.getCmtUserByUserName(getRemoteUserName());
      courseHandler.joinCourse(currentUser,currentCourse)
       CustomMessage.createMessage("course_joined");
      }


      Thank you for your answers!
      NSchweig