3 Replies Latest reply on Apr 15, 2007 8:36 PM by chubinator

    Scope and Best Practices

    chubinator

      Hello,

      I'm very new to Seam and have been searching around the documentation and forums for some guidelines and best practices with regard to component scope.

      The documentation mentions in several places that SESSION scope is frowned upon and/or used sparingly. Yet, nearly all the examples use it, especially those dealing with the DataModel.

      I can see how its not scalable to keep a large data model in memory for the duration of a user's session, but it seems equally non-scalable to query the database each time the user interacts with the page it supports.

      I've experimented with long running conversations, etc, but then I have to make sure I end the conversation somehow when the user navigates away from the page.

      I guess before I get myself too contorted trying to figure out the best way to do something, I thought I'd ask the users how they use Scope. When do you use SESSION and when do you use CONVERSATION? Do you use long running or the temporary conversations? If long running, how to handle the user jumping to another page via a link or bookmark?

      Also, if you have a page with a table for example that supports paging, what scope do you use?

      Thanks in advance for your help,
      Mark

        • 1. Re: Scope and Best Practices

           


          I can see how its not scalable to keep a large data model in memory for the duration of a user's session, but it seems equally non-scalable to query the database each time the user interacts with the page it supports.


          I consider both bad practice. You should only fetch the data you actually need - not the whole data from the database. If you're resultset is large you should scroll over the resultset and fetch only the data actually displayed.

          This is where converstations come in. You can have different subsets of a resultset to display in different windows. This is not possible with session scope as the results would overwrite each other.

          The other advantage is that you can "clean out" the conversation context with a single annotation while you have to remove components from session scope explicitly.

          However sometimes you do want that data is shared between different browser windows. This is were you have to use session scope.


          I thought I'd ask the users how they use Scope?


          IMHO it boils down to this: If your user is only using a single browser instance and you never and your long running converation performance will be exactly like using session scope. If your user uses multiple browser windows to access your application that do not share data you have to use conversations. If you end conversation now and then you will save memory compared to using session scope you do not clean.

          • 2. Re: Scope and Best Practices
            pmuir

            I used your questions to create a wiki entry - http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamScopeFAQ and merged in Felix's answers as well

            • 3. Re: Scope and Best Practices
              chubinator

              Thank you for the prompt response and for the Wiki!

              I've been working on a paging and sortable datatable view, but kept fumbling around with parameters (firstRow, noRows, sort column, etc) and how best to pass them around/scope them.

              I landed on a temporary conversation and using page parameters for the parameters not explicitly used in the page (sort column). It seems to work, but was wondering if changing it to a long running conversation made more sense. But then I worried about the "lingering" conversation if the user navigated away in an unexpected way. As you said in the Wiki, perhaps its not worth worrying about since it will eventually time out.

              I'll take a look at the Seam gen tool as suggested as well and see how does things.

              Thanks again!