3 Replies Latest reply on Nov 29, 2006 6:01 AM by Paul Bakker

    Seam + ScopeType.EVENT

    Gregory Nikle Apprentice

      Hi,
      Can anyone tell me in with cases, U use Event scope, and demonstrate me example.

      Is this even useful?

        • 1. Re: Seam + ScopeType.EVENT
          Paul Bakker Newbie

          This is comparable with a request scope. For exampe a page with a backing bean that can submit data, the backing bean can give feedback, but the data is not saved after that.

          Example:

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml"
           xmlns:s="http://jboss.com/products/seam/taglib"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:c="http://java.sun.com/jstl/core">
          <body>
          <ui:define name="body">
           <h:form id="frm_Hello">
           Please fill in your name: <h:inputText id="txt_Name"
           value="#{hello.name}" />
           <h:commandButton id="btn_sayHello" value="Say Hello!"
           action="#{hello.sayHello}" />
           <br/>
           <h:outputText id="greeting" value="Hello #{hello.name}"
           rendered="#{not empty hello.name}" />
           </h:form>
          </ui:define>
          </body>
          </html>
          


          package seamdemo.hello.backingbeans;
          
          import javax.ejb.Remove;
          import javax.ejb.Stateful;
          
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Destroy;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          
          @Stateful
          @Scope(ScopeType.EVENT)
          @Name("hello")
          public class HelloBean implements Hello {
           private String name;
          
           public String getName() {
           return name;
           }
          
           public String sayHello() {
           return "";
           }
          
           public void setName(String name) {
           this.name = name;
           }
          
           @Remove @Destroy
           public void destory() {
           }
          }
          


          After showing the entered name, the name is not saved. So if you reload the page, the textfield is empty again.

          • 2. Re: Seam + ScopeType.EVENT
            Gregory Nikle Apprentice

             

            "paul@xfact.nl" wrote:
            This is comparable with a request scope. For exampe a page with a backing bean that can submit data, the backing bean can give feedback, but the data is not saved after that.

            After showing the entered name, the name is not saved. So if you reload the page, the textfield is empty again.


            Soo what's the different betwen Event & Page scope?

            • 3. Re: Seam + ScopeType.EVENT
              Paul Bakker Newbie

              That's still a little unclear to me too. One big difference is that @Page can't be use in session beans.