6 Replies Latest reply on Jun 29, 2008 4:40 AM by Jose Larghi

    Stateless wiht state?

    Jose Larghi Newbie

      Hi people, Somebody know why an attribute of stateless exists between various request?
      I have a stateless with an attribute, in the first invocation i instanciate it, after... in the second invocation, before instanciate it again, continues instanciated.


      Is normal this?


      Thanks.

        • 1. Re: Stateless wiht state?
          Sander S Newbie

          The object is returned to the pool. When requesting a new object they will come from the instance pool, how many objects are in the pool depends on your config.


          Because you'll probably use only one user for testing/dev you get the same instance the whole time.


          Just don't use object scoped vars in stateless beans, there are statefull beans to do that.

          • 2. Re: Stateless wiht state?
            Jose Larghi Newbie

            Hi Sander, thanks for your answer.


            Yes, i use a stateless with an attribute for manage the crud operations. This is bad? I think that use a stateful for this is too much.


            this is my code:




            @Stateless
            @Name("proyectosAction")
            public class ProyectosActionBean implements ProyectosAction {
            
                    @PersistenceContext
                    EntityManager em;
            
                    private Proyecto nuevoProyecto;
            
                    public String editProyecto(Long id) {
                            this.setNuevoProyecto(em.find(Proyecto.class, id));
                            return "editarProyecto";
                    }
            
                    public String guardadProyecto() {
                            em.merge(this.getNuevoProyecto());
                            return this.listarProyectos();
                    }
            



            I have an error when try paste my xhtml here :(.


            If I don't set the attribute nuevoProyecto then I have an error, when the page render I obtain the error nuevoProyecto is null'


            Thanks and sorry for my writing. I learn.

            • 3. Re: Stateless wiht state?
              Sander S Newbie

              Then make it a statefull bean.


              I don't actually know when to use statefull and stateless in seam because I don't use ejb3 for my components. But look at the examples how is it handled in there you'd might get something out of it.


              Furthermore; some reading on ejb3 could help you a bit understanding it all. Why are you using it in the first place, why not using only the servlet?

              • 4. Re: Stateless wiht state?
                System Administrator Expert

                If the EJB is a backing bean for your JSF, then you should use a SFSB, especially if you need to maintain the client's state (@Begin and @End Seam annotations).


                Stateless session beans are typically used when you don't need to maintain the client's state (e.g. a credit card verification service that can also be exposed as a web service).


                read the Seam ref pdf that comes with the Seam distro as well as JSR 220 core.  also look at the hotel booking example code.

                • 5. Re: Stateless wiht state?
                  Jose Larghi Newbie

                  Hi thanks to both. Yes, I use a SLSB whit a conversation, it is the correct manner.
                  I should love more to the SFSB and use less SLSB :)


                  Thanks again!
                  Bye.

                  • 6. Re: Stateless wiht state?
                    Jose Larghi Newbie

                    I want say SFSB, no SLSB