6 Replies Latest reply on Jan 24, 2008 12:01 PM by pmuir

    Ending default scope SFSB's needed?

    oberiko

      Hello.

      If I have a stateful session bean in the default (i.e. undeclared) conversation scope, do I need (or is it good practice) to end it somehow? Or can I just let Seam take care of it?

        • 1. Re: Ending default scope SFSB's needed?
          nickarls

          Seam should take care of the recycling when the conversation ends. Of course, if there are and special cleanups to be made in order to release special resources, you can use a @Destroy method

          • 2. Re: Ending default scope SFSB's needed?
            oberiko

            Yeah, but I'm not explictly calling @Start or @End on any of my methods. How does Seam determine when I'm finished with this session bean?

            package org.domain.myProject.session;
            
            import static javax.persistence.PersistenceContextType.EXTENDED;
            
            import java.util.List;
            
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.ejb.Stateless;
            import javax.persistence.EntityManager;
            
            import javax.persistence.PersistenceContext;
            
            import org.domain.myProject.entity.EmailAddress;
            import org.domain.myProject.entity.Person;
            import org.domain.myProject.session.local.EditPersonLocal;
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Destroy;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Out;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.contexts.Context;
            import org.jboss.seam.contexts.Contexts;
            import org.jboss.seam.faces.FacesMessages;
            import org.jboss.seam.log.Log;
            
            @Stateful
            @Name("editPerson")
            //@Scope(ScopeType.EVENT)
            public class EditPersonForm implements EditPersonLocal {
            
             @Logger
             private Log log;
            
             @In
             FacesMessages facesMessages;
            
             @PersistenceContext(type = EXTENDED)
             private EntityManager em;
            
             @In(required=false)
             @Out(scope=ScopeType.PAGE)
             private Person person;
            
             @In(required=false)
             @Out(required=false)
             private EmailAddress emailAddress;
            
             public void addEmail() {
             person.addEmailAddress(emailAddress);
            
             log.info("Email address " +emailAddress.getUrl() + " Added to "+ person.getName());
            
             emailAddress = new EmailAddress();
             }
            
             public void removeEmail(EmailAddress emailAddress) {
             log.info("Removing Email address " +emailAddress.getUrl());
             person.removeEmailAddress(emailAddress);
             }
            
             public void savePerson() {
             if (person.getId()!=null)
             em.merge(person);
             else
             em.persist(person);
            
             //Note that the id of our person was generated and populated.
             facesMessages.add("Person was saved with an id of "+ person.getId());
            
             log.info(person.getName() +" was saved.");
             }
            
             public void editPerson(Person person) {
             log.info("Getting Id: " + person.getId());
             person = (Person) em.createQuery("from Person p where p.id =" +person.getId()).getSingleResult();
             }
            
             @Destroy @Remove
             public void destroy() {}
            
            }
            


            • 3. Re: Ending default scope SFSB's needed?
              nickarls

              Then you are in a temporary conversation and you're done with the bean when you are done with the conversation, which is about when the request ends.

              • 4. Re: Ending default scope SFSB's needed?
                oberiko

                Really? That's very useful then. I've been smacking my head trying to figure out how to get what I needed (ideally something similar to the Page scope since I'm trying to avoid the session scope, but that's not allowed for stateful beans) until I just tried the default and it worked.

                Thank you.

                • 5. Re: Ending default scope SFSB's needed?
                  nickarls

                  Well, at least that's I'll believe until someone corrects me...

                  • 6. Re: Ending default scope SFSB's needed?
                    pmuir

                    Yes, as long as you have a @Remove method to call.