11 Replies Latest reply on Jan 25, 2006 11:26 PM by Aaron

    Managed-Beans -> SLSB

    Aaron Novice

      I'm having a difficult time converting my Faces app to a Seam App. Mostly, I'm having a hard time with moving my managed-beans to SLSB / Entity

      For example, I have a managed session bean called "currentUser" which is of type app.entity.User, basically doing what the DVD-Store did, by grabbing the username, sending it to a SLSB, and returning a User object.

      I also have a 2 generic managed request beans, also of type app.entity.User.

      That's three different managed beans, all of type app.entity.User. I have three of them, as there is a page that requires all three user objects to be instantiated with 3 different Users (the currentUser, an assignedUser, and an ownerUser).

      But, since I no longer have managed-beans to "define" my different objects, where do they get defined in seam?

      Obviously, I shouldn't have 3 different EntityBeans with different @Name annotations.

      Anyone?

      Thanks!!

        • 1. Re: Managed-Beans -> SLSB
          Aaron Novice

          I believe I have hit a time of reverence and wisdom, and would like someone to check my knowledge.

          I think my largest problem, is in thinking that the object has to already be instantiated, or at least defined BEFORE calling it from a Faces page:

          I guess that's not the case. In the SessionBean, the object:

          @Stateless
          public class blah{
          @In @Out private User currentUser;
          @In private User assignedUser;
          @In private User ownerUser;
          }
          

          Those objects aren't defined anywhere else. As long as the JSF page's action submits to this SLSB, the objects are created (if need be) by this:
          <h:inputText value="#{currentUser.username}" />
          <h:inputText value="#{assignedUser.username}"/>
          

          Is that correct?

          And the @Out annotation can be used on the next page that's rendered.

          So, if I'm correct, then here's my next question:

          If the User Entity Bean is set to a SESSION context, does that mean my request variables also eat up memory?

          For example, only the currentUser variable should be stored in the SESSION. But, since assignedUser and ownerUser are both objects of the User class, which, in turn, is defined as a SESSION component, are those two objects also stored in the SESSION, even though I'm only using them as REQUEST objects?

          Thanks for helping me understand.

          • 2. Re: Managed-Beans -> SLSB
            js8523 Novice

            Hi

            Unfortuneatly currently you cannot use the same object outjected many times


            @Stateless
            public class blah{
            @In @Out private User currentUser;
            @In private User assignedUser;
            @In private User ownerUser;
            }


            There was some talk about allowing this but I don't know how far they got.

            James

            • 3. Re: Managed-Beans -> SLSB
              Gavin King Master

               

              Unfortuneatly currently you cannot use the same object outjected many times


              Actually you can do this, its fine, you just have to explicit the scope:


              @In @Out(scope=SESSION)
              private User assignedUser;



              An object can be bound to as many context variables as you like. No problem.

              The only limitation is that it will only be *automatically instantiated* for the context variable that matches the @Name annotation of the component.

              So if "assignedUser" is not the @Name of User, you have to instantiate it yourself and bind it to the context variable yourself.

              Does this make sense?

              Note that there is a user-written patch in CVS to allow an @Roles annotation that will removed even this limitation.

              It sounds like the original question is a request for the @Roles stuff. Perhaps I'll apply that patch before releasing beta2.

              • 4. Re: Managed-Beans -> SLSB
                Gavin King Master

                 

                "Neelixx" wrote:
                I think my largest problem, is in thinking that the object has to already be instantiated, or at least defined BEFORE calling it from a Faces page:


                Not sure exactly what you mean, but as I said, the only case where instantiation happens automatically (when referencing the context variable in a JSF value binding or method binding or from @In(create=true)) is when the context variable name is the @Name of a component.

                Those objects aren't defined anywhere else. As long as the JSF page's action submits to this SLSB, the objects are created (if need be) by this:
                <h:inputText value="#{currentUser.username}" />
                <h:inputText value="#{assignedUser.username}"/>
                

                Is that correct?


                This would not work, because Seam does not currently allow multiple @Names for a single component. You need the @Roles patch.

                If the User Entity Bean is set to a SESSION context, does that mean my request variables also eat up memory?

                For example, only the currentUser variable should be stored in the SESSION. But, since assignedUser and ownerUser are both objects of the User class, which, in turn, is defined as a SESSION component, are those two objects also stored in the SESSION, even though I'm only using them as REQUEST objects?


                No, each context variable has its own scope. You can do

                @Out(scope=REQUEST)
                private User assignedUser;


                But, again, what you really need is @Roles. Each @Role will have its own scope.

                Make sense?



                • 5. Re: Managed-Beans -> SLSB
                  Rob Jellinghaus Novice

                  Gavin, can you give an example of some code using @Roles? Or is there a JIRA for this?

                  Thanks!
                  Cheers,
                  Rob

                  • 6. Re: Managed-Beans -> SLSB
                    Aaron Novice

                    I, too, am interested in @Roles, as this seems to be the only road-block in using Seam for my application.

                    • 7. Re: Managed-Beans -> SLSB
                      Gavin King Master

                      OK, what I will do is tray and commit this code sometime tomorrow.

                      • 8. Re: Managed-Beans -> SLSB
                        Gavin King Master

                        It is committed.

                        • 9. Re: Managed-Beans -> SLSB
                          Aaron Novice

                          So, in looking over http://anoncvs.forge.jboss.com/viewrep/JBoss/jboss-seam/src/main/org/jboss/seam/annotations/Roles.java?r=1.1, I would use the annotation like the following, in my case:

                          
                          @Entity
                          @Name("user")
                          @Scope("Session")
                          @Roles("assignedUser","ownerUser")
                          public class User implements Serializable {
                          // blah
                          }
                          
                          --------- JSF -----------
                          
                          <h:inputText value="#{assignedUser.username}" />
                          <h:inputText value="#{ownerUser.username}" />
                          
                          


                          At this point, all three context variables are valid and will be auto-instantiated to the User Entity Bean, if it does not currently exist.

                          Am I correct in thinking that?

                          • 10. Re: Managed-Beans -> SLSB
                            Gavin King Master

                             

                            @Entity
                            @Name("user")
                            @Scope(SESSION)
                            @Roles({@Role("assignedUser"),@Role("ownerUser")})
                            public class User implements Serializable {
                            // blah
                            }



                            I just committed documentation for this stuff. Take a look at the docs.

                            • 11. Re: Managed-Beans -> SLSB
                              Aaron Novice

                              Just got it. Thanks.