4 Replies Latest reply on Nov 15, 2007 1:14 PM by jfrankman

    Stateless Session Bean and @Out

    jfrankman Novice

      I am trying to understand when Stateless session beans should be used within the Seam framework. I orginally thought I could outject from a Stateless Session Bean to my JSF page as follows:


      @Stateless
      @Name("myBeanA")
      public class MyBeanAImpl implements MyBeanA
      {
       @Out(required = true)
       List<Rptprdmgbinder> propertyBinders;
      
       public String showPropertyDamageBinders()
       {
       Date filterDate;
       Calendar cal=Calendar.getInstance();
       cal.set(2007, 10,5);
       filterDate=cal.getTime();
       propertyBinders=countyOfficeDocService.getPropertyBinders(worker.getOffice().getId(), filterDate);
       return "";
       }


      But this only works if I specify conversation scope on the outjected variable:

      @Stateless
      @Name("myBeanA")
      public class MyBeanAImpl implements MyBeanA
      {
       @Out(required = true,scope=ScopeType.CONVERSATION)
       List<Rptprdmgbinder> propertyBinders;
      
       public String showPropertyDamageBinders()
       {
       Date filterDate;
       Calendar cal=Calendar.getInstance();
       cal.set(2007, 10,5);
       filterDate=cal.getTime();
       propertyBinders=countyOfficeDocService.getPropertyBinders(worker.getOffice().getId(), filterDate);
       return "";
       }


      I still need to study the inner workings of a Stateless Session bean, but can anyone explain cases or examples where using a stateless session bean within a Seam application would be advisable? Does it ever make sense to use a Stateless session bean for an Action Listener by outjecting a variable into a conversation scope (as shown above) or is it better to use a Stateful session bean?

        • 1. Re: Stateless Session Bean and @Out
          Monkey Den Master

          I might have guessed that CONVERSATION scope was the default but why are you opposed to specifying it? I think it will be outjected to CONVERSATION if the bean itself had this as it's scope.

          • 2. Re: Stateless Session Bean and @Out
            jfrankman Novice

            From the documentation for the @Out annotation:

            Specifies the scope to outject to. If no scope is explicitly specified, the default scope depends upon whether the value is an instance of a Seam component. If it is, the component scope is used. Otherwise, the scope of the component with the @Out attribute is used. But if the component scope is STATELESS, the EVENT scope is used. - http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.2/doc/seam/api/org/jboss/seam/annotations/Out.html

            Here is how I understand it

            If scope is explicitly specified:
             the specified scope is used
            otherwise:
             if the outjected variable is a seam component:
             The seam component's scope is used
             otherwise
             If scope of the component outjecting the variable is stateless
             event scope is used
             otherwise
             the scope of the component outjecting the variable is used

            Looking at my example I would say that the List I am trying to outject is not a seam component. (The objects contained in the list are seam components, but the List being outjected is not). That is based on my understanding that a Seam component is declared with the @Name annotation. Is this correct? If anyone can confirm this or set me straight I would appreciate it.

            This brings up more questions.

            1. What is the difference between doing this:

            @Stateless
            @Name("clientTransmittalLineItemAction")
            public class MySessionBeanImpl implements MySessionBean
            {


            and this?:
            @Stateful
            @Name("clientTransmittalLineItemAction")
            @Scope(ScopeType.STATELESS)
            public class MySessionBeanImpl implements MySessionBean
            {


            2. Is the second option even possible?
            3. T or F? if you have a stateless session bean there is not any point in using the @Scope annotation.
            4. T or F? If you have a stateful session bean you can specify any scope using the @Scope annotation other than ScopeType.STATELESS


            It seems that 90% of Seam examples in books and online all use SFSB. I am trying to understand when and how a SLSB would be better to use than a SFSB. Any help is appreciated.


            • 3. Re: Stateless Session Bean and @Out
              Pete Muir Master

              1) The stateless scope is not very useful - put that bean into EVENT scope and it makes more sense
              3) True, as the obtaining the instance is managed by EJB3 so instance variables won't be remembered
              4) True.

              SLSB is useful when your data needs no state (e.g. view only).

              • 4. Re: Stateless Session Bean and @Out
                jfrankman Novice

                Thanks Pete for the answers. That helps me alot. I will crack open an EJB book this weekend to get a little more detail.