5 Replies Latest reply on Mar 3, 2006 8:22 PM by Gavin King

    Show registration user information !

    Eric Chow Apprentice

      Hello,

      In the Registration example, how can show the registered user list after register a user under the registration form?

      For example, in the registration example, it will show "Register success ..." after registered a user, right? I just want to show the registration form again after successfully register a user and under the form, show a user list (all the users in the DB including the new registered one).

      How to do that ?

        • 1. Re: Show registration user information !
          Gavin King Master

          Something like this (untested):

          @Name("userListFactory")
          @Stateless
          public class UserListFactoryBean implements UserList {
          
           @Out(scope=EVENT) List<User> userList;
           @PersistenceContext EntityManager em;
          
           @Factory("userList")
           public void fetchUserList()
           {
           userList = em.createQuery("from User").list();
           }
          
          
          }
          


          • 2. Re: Show registration user information !
            Cory Virok Newbie

            Not exactly on point with the original question...

            I thought that is a bean was @Stateless then it couldn't use @Out fields. Would you be able to point me in the direction of a document explaining all the different scopes in terms of stateless and stateful beans and maybe a little on stateless beans called in a Conversation context, (if that even makes sense)?

            Lastly, what's the difference between getting an EntityManager these two ways:

            
            @In(create = true)
            EntityManager entityManager;
            
            @PersistenceContext(type = PersistenceContextType.EXTENDED)
            EntityManager entityManager;
            
            


            Thanks a bunch,
            - Cory

            • 3. Re: Show registration user information !
              Jim Hazen Expert

              @Stateless components can outject fields into a wider scope via @Out(scope=...) without issue. What probably doesn't make sense is a class annotation of

              @Stateless
              @Scope(CONVERSATION)
              public class foobar {...}
              


              In Gavin's example he needed to outject his user list into a scope that JSF would see (EVENT and above). Had he not specified a scope attribute, the default scope of the component would have been used. Since the component is stateless, the object would never have made it back to the JSF layer. In fact you will always need to specify the scope attribute when outjecting from a stateless bean.

              The Seam documentation has a nice section on the supported contexts.

              http://docs.jboss.com/seam/reference/en/html/concepts.html#d0e1733

              Your second question probably deserves a post by itself. I believe that @PersistenceContext is a standard EJB3 annotation. You can additionally configure Seam to manage a persistence context outside of EJB3. There's an example of how to do that below. That method uses the @In annotation.

              http://docs.jboss.com/seam/reference/en/html/configuration.html#d0e3059


              • 4. Re: Show registration user information !
                Cory Virok Newbie

                aha. So the @PersistenceContext explains why I was getting annoying LazyInitialization exceptions since the container was managing my EntityManager instead of Seam. Switching to the @In method worked to fix that problem. I got confused because a lot of the examples use @PersistenceContext instead of letting Seam manage it for them.

                As for the @Out(scope = EVENT)...

                I gather that doing this is basically equivalent of saving a session variable, ie. HttpSession.set(). I think it's starting to click now. It's taking a few more reads over the documentation.

                I appreciate the help and keep up the good work!
                - Cory

                • 5. Re: Show registration user information !
                  Gavin King Master

                  @PersistenceContext(type=EXTENDED) in a stateful session bean is another way to solve the LIE problems.

                  @Out(scope=EVENT) puts things the in the Seam EVENT context (the web HttpRequest context), not the SESSION context.