2 Replies Latest reply on Dec 18, 2008 6:42 AM by Naresh Bhatia

    Scope for a single form

    Naresh Bhatia Newbie

      A common usecase in web applications is a single form with a submit button. When the user submits the form, if any field fails validation, redisplay the form with an error message, but make sure all the valid fields are kept intact. What is the best approach to handle this usecase in Seam?


      - Should the backing bean be in conversation scope? If so, when and where should the conversion start and end? The examples I have seen are mostly multi-page and start the conversation on an action from a page that is outside the conversation. In my usecase, I have only one page, but it can be reached from many different pages? It would be nice not to have to start the conversations from all those other pages. Is there a way to start the conversation on the first rendering of a page?


      - Some examples I have seen put the backing bean in the session scope. Is this really necessary? Seems a bit of an overkill.


      Anyway, any guidance or best practices much appreciated.


      Thanks.
      Naresh

        • 1. Re: Scope for a single form
          Ingo Jobling Master

          Hi Naresh,


          You probably want to create a Seam component, to act as the backing bean, in CONVERSATION scope.  Use of SESSION scope for this sort of thing is discouraged.


          You can start your conversation in yourpage.xml like this:


          <begin-conversation flush-mode="MANUAL" join="true" />



          To take full advantage of Seam, you can also add something like this:


          <navigation from-action="#{controller.persist}">
               <rule>
                    <end-conversation />
                    <redirect />
               </rule>
          </navigation>



          This will avoid the warning about reposting that the browser will pop up if the user refreshes the page, or hits the back button, after successfully submitting the form.



          • 2. Re: Scope for a single form
            Naresh Bhatia Newbie

            Thanks so much you Ingo! Your advice is dead on. My page is now working very smoothly.