1 Reply Latest reply on Jun 21, 2008 3:10 AM by Laurent Mallet

    page vs. event scope in Seam

    System Administrator Expert

      what exactly is the difference between page and event scope and some examples of when you'd use each one?


      When does the page and event scope end or get destroyed (go out of scope)?


      Here is one from Dan Allen's
      article


      package example;
      
      @Name("userList")
      public class UserListBean {
          @In
          private UserService userService;
      
          @Factory(value = "users", scope = ScopeType.PAGE)
          public List getUsers() {
              return userService.findAll();
          }
      }



      What would be the difference if the following code was used instead?



      package example;
      
      @Name("userList")
      public class UserListBean {
          @In
          private UserService userService;
      
          @Factory(value = "users", scope = ScopeType.EVENT)
          public List getUsers() {
              return userService.findAll();
          }
      }



      The Yuan book states the following on pg. 84:


      Event: this is the narrowest stateful context in Seam.  Components in this context maintain their states throughout the processing of a single JSF request.


      Page: components in this context are tied to a specific page.  You can have access to those components from all events emitted from this page.

        • 1. Re: page vs. event scope in Seam
          Laurent Mallet Newbie

          Event is the shortest statefull ScopeType. Page is longer. Think about Ajax processing. If you have a myComponent component with
          page Scope. At component's creation, it has an integer property with 0 value. And you have an add action method. When you use this action, counter is incremented.The way to reset counter is to refresh the counter.


          With Event Scope, the value is always 0.