2 Replies Latest reply on Apr 27, 2006 6:22 PM by gavin.king

    Invoke alway the factory

    udo.krass

      Hi,

      i have a little problem.
      I store an entity existingUser in my session-Context when a request page is called with the username as request parameter.

      @Stateless
      @Name("userBox")
      @Scope(org.jboss.seam.ScopeType.SESSION)
      @Interceptors(SeamInterceptor.class)
      public class UserBoxAction implements UserBox {
       private static final Logger log = Logger.getLogger(UserBoxAction.class);
      
       @Out
       private User existingUser;
      
       @In
       private transient Context sessionContext;
      
       @RequestParameter("username")
       private String username;
      
       @PersistenceContext
       private EntityManager em;
      
      
      @Factory("existingUser")
       public void listUserDetails() {
       //if the user comes from the guestbook back and does not start a request
       if (username.equals("")||username==null)
       {
       username = existingUser.getUsername();
       }
       log.info("existingUser will be injected" + username);
       existingUser = (User) em.createQuery(
       "from User where username=:username").setParameter("username",
       username).getSingleResult();
       //set the selected User in the Session, because nothing else will work
       // properly
       sessionContext.set("existingUser", existingUser);
      }
      }
      


      But when i call this page twice in the same session with another username, the factory isn't working. That's right, because the existingUser entity is known in the context now. But that's not what i want. How can i invoke the factory on every request and override the existingUser entity?

      Thanx in advance.

      Udo