4 Replies Latest reply on May 9, 2007 10:55 AM by Phil Haigh

    Scoping using Seam App Framework

    Phil Haigh Novice

      Hi,

      I'm sure this will be a really basic thing I'm missing... but..

      I have a simple CRUD application using entityhome etc in components.xml

      This works fine except for where I have validation on the form, and a non-string property (e.g. I am entering a "Vacancy" that has a "Company" object). If the form is submitted and fails validation, then the company is set back to null.

      <factory name="company" value="#{companyDAO.instance}" />
       <fwk:entity-home name="companyDAO"
       entity-class="model.Company">
       </fwk:entity-home>
      
      
       <factory name="vacancy" value="#{vacancyDAO.instance}" />
       <fwk:entity-home name="vacancyDAO"
       entity-class="model.Vacancy">
       </fwk:entity-home>
      
      


      I'm selecting the company for the addvacancy page on the preceeding page:

      <h:selectOneRadio styleClass="radiolist" layout="pageDirection" value="#{vacancy.company}" >
      <snip>
       <h:commandButton styleClass="button" value="Submit" action="/addvacancy.xhtml"/>


      Now, I can solve this problem by setting the scope of my entityhomes to session... but then the object isn't cleared after adding (next time you go to add one, you see all the old values). If I set the scope to page, it works, but then I can't edit the objects - calls to .update return the "updated" string, but don't do any database activity.

      I presume either there is:

      1. A funky way of doing this kind of thing that I've missed
      2. A way to configure conversations to avoid this issue (can this be done using entityhomes configured in components.xml?)
      3. A way to tell Seam to clear objects after a persist or update

      Any help would be greatly appreciated!



        • 1. Re: Scoping using Seam App Framework
          Pete Muir Master

          Huh? What problem are you trying to solve?

          • 2. Re: Scoping using Seam App Framework
            Phil Haigh Novice

            If I use default scoped components then when I submit the form and validation fails, it loses all values on the object (presumably because the object itself falls out of scope)

            If I use page scoped components then the above is solved (since validation occurs on the same page), and I can add an object. However, I then find that going to my edit page, and calling .update on the object returns the "updated" string, but does not update the DB

            If I use session scoped components, it all works, except that the object doesn't go away, so I can add an object, edit it, but then when I go to add another one, I've still got the previous objects values on the form.

            Does that make sense?

            • 3. Re: Scoping using Seam App Framework
              Pete Muir Master

              Ah, I see. You want a long running conversation

              • 4. Re: Scoping using Seam App Framework
                Phil Haigh Novice

                Thanks :-)

                For anyone else, this is the simplest solution I ended up with:

                <in pages.xml>

                 <page view-id="*">
                 <navigation>
                 <rule if-outcome="updated">
                 <redirect view-id="/confirm.xhtml"/>
                 </rule>
                 <rule if-outcome="persisted">
                 <redirect view-id="/confirm.xhtml"/>
                 </rule>
                 </navigation>
                 </page>
                
                 <page view-id="/confirm.xhmtl">
                 <end-conversation/>
                 </page>
                
                 <page view-id="/anaction.xhtml" >
                 <begin-conversation/>
                 </page>


                etc