5 Replies Latest reply on Nov 29, 2006 1:39 PM by Wenhu Guan

    Seam promote bad design?

    Wenhu Guan Newbie

      I know it is a small problem, but when i go through the seam document (all documents,articles in the internet), I found all the action code actually has mixed responsibility: page navigation and business logic. See the following code from book demo:
      @Stateless (1)
      @Name("register")
      public class RegisterAction implements Register
      {

      @In (2)
      private User user;

      @PersistenceContext (3)
      private EntityManager em;

      @Logger (4)
      private Log log;

      public String register() (5)
      {
      List existing = em.createQuery("select username from User where username=:username")
      .setParameter("username", user.getUsername())
      .getResultList();

      if (existing.size()==0)
      {
      em.persist(user);
      log.info("Registered new user #{user.username}"); (6)
      return "/registered.jsp"; (7)
      }
      else
      {
      FacesMessages.instance().add("User #{user.username} already exists"); (8)
      return null;
      }
      }


      }

      the register function actually has dual resonsibility which broke a fundametal OO design principle:Single-Resonsibility-Principle. and all the generated seam code is same.

      Would it be better that an official tutorial providing better sample code?

      No offense. I do like SEAM.

      Thanks

        • 1. Re: Seam promote bad design?
          Paul Bakker Newbie

          To my opinion this is a pretty standard way of using JSF, so it's quite logical to map the same examples to Seam.
          I do agree that it's not the best seperation of concerns, but on the other hand it works pretty well like this.
          Specially for smaller applications I see no good reasons to do differently.

          • 2. Re: Seam promote bad design?
            Pete Muir Master

            You can provide more separation by returning a logical outcome from the action method and mapping that to a view from a naviation rule in faces-config.xml. IMO this provides the necessary split between business logic and navigation.

            I guess the Seam examples return view-ids directly as it makes the example more readable (one less place to look).

            • 3. Re: Seam promote bad design?
              Edwin van der Elst Newbie

              I use pageflows for the navigation, the beans don't contain any navigation and I call the action methods using expressions in the flow.
              In the views, the buttons return the transitions to use.
              It is a pretty clean seperation I think.

              • 4. Re: Seam promote bad design?
                Ning Zhao Apprentice

                Seam + jpdl pageflow really separate concerns very cleanly. You may want to have a look at the number guess example. There's pure business logic in the action class. Another example is DVD store, the newuser flow and the checkout flow.

                • 5. Re: Seam promote bad design?
                  Wenhu Guan Newbie

                   

                  "ellenzhao" wrote:
                  Seam + jpdl pageflow really separate concerns very cleanly. You may want to have a look at the number guess example. There's pure business logic in the action class. Another example is DVD store, the newuser flow and the checkout flow.


                  Thanks, I will look at the examples you mentioned. Another newbie question, can the statefull action or stateless action's interface be remote, so that all the ejb module located on a separate physical machine? does anyone manage to do this?