7 Replies Latest reply on Sep 5, 2007 2:32 PM by Bradley Smith

    renew the @Factory

    Sergio R Pantano Newbie

      I´m trying to make a page to insert data and when submitted it returns to the same page insert other one. But when return the object has the data of previous object.
      The object was created by @Factory:

      @Factory("license")
      public License work() {
       return getInstance();
      }


      When submit the action method do:
      public String persistAndContinue(){
       super.persist();
       setInstance(new License());
      }


      The getInstance has a new License object but the "license" still has the previous data.

      How to do this correct?


      Ps.: I´m using Jboss Framework
      The code of pages.xml is
      <navigation from-action="#{licenseHome.persistAndContinue}">
       <end-conversation/>
       <redirect view-id="/license/add.xhtml"/>
      </navigation>


      thanks for help.

        • 1. Re: renew the @Factory
          Bradley Smith Master

          Let's say your Seam component that contains this @Factory is session scoped; then you need to remove the current license from the session context. Example:

          public String persistAndContinue(){
           super.persist();
           Contexts.getSessionContext().remove("license");
           setInstance(new License());
          }
          


          Hope that helps.


          • 2. Re: renew the @Factory
            Sergio R Pantano Newbie

            It didn´t works!

            When submit the value in fields are in screen and when I press the submit button again give error.

            • 3. Re: renew the @Factory
              Sergio R Pantano Newbie

              the interesting is: after submit the conversation are changed but the fields still there.

              • 4. Re: renew the @Factory
                Bradley Smith Master

                 

                It didn´t works!


                Well, you should probably post your entire component then and the markup that you claim is 'submit the action'.

                • 5. Re: renew the @Factory
                  Sergio R Pantano Newbie

                  ok, here go!

                  in my add.xhtml page I put:

                  #{messages['Name']}:
                  <h:inputText id="name" size="30" value="#{license.name}">
                   <s:validate />
                   <a4j:support event="onblur" reRender="outMessageLicensee" />
                  </h:inputText>
                  
                   <s:link action="#{licenseHome.persistAndContinue}">
                   <h:outputText value="#{messages['Tosavecont']}"/>
                  </s:link>
                  


                  the add.page.xml:

                  <page no-conversation-view-id="list.xhtml">
                  
                   <begin-conversation join="true"/>
                  
                   <navigation from-action="#{licenseHome.persistAndContinue}">
                   <end-conversation/>
                   <redirect view-id="add.xhtml"/>
                   </navigation>
                  
                  </page>
                  


                  and the class:

                  @Name(value = "licenseHome")
                  public class LicenseHome extends EntityHome<License> {
                  
                   @Override
                   protected License createInstance() {
                   license = new License();
                   return license;
                   }
                  
                   @Override
                   @Factory(value = "license")
                   public License work() {
                   return getInstance();
                   }
                  
                   public String persistAndContinue() {
                   super.persist();
                   Contexts.getSessionContext().remove("license") ;
                   setInstance(new License());
                  
                   return "";
                   }
                  
                   public void setLicenseId(Long id) {
                   setId(id);
                   }
                  
                   public Long getLicenseId() {
                   return (Long) getId();
                   }
                  }


                  • 7. Re: renew the @Factory
                    Bradley Smith Master

                    Hmmm....

                    EntityHome isn't well documented in Seam 1.2.1 (which is what I currently use) and so without reviewing the EntityHome impl code in Seam, I'll have to guess a bit here.

                    On closer inspection of your code, it looks like whether createInstance() is invoked or persistAndContinue() is invoked, both impl's as shown will produce a newly instantiated license.

                    However, you're saying that the 'data of previous object' is in "license" - are you submitting to a session- or conversational-scoped component? If you are, are you also outjecting license back to session or conversation?