5 Replies Latest reply on Apr 7, 2011 8:12 PM by kragoth

    Unintentional Entity Update when changing form

    bemar

      Hello,


      I'm currently a little bit confused about my seam-gen project.
      I have a Change my Properties page in the admin area of my project.


      At the first side you can change your personal data. Then you can click on Preview or Cancel. With click on preview the data will be send back to the bean but no updated by executing a method called confirm which only returns a string confirmed and starts the conversation with the (@Begin) annotation.
      But the entity will also be updated by saving it to database. I guess this will be triggerd from inside the framework.


      Can someone explain why. Do I start the conversation to late?


      Thx and best regards


      Ben



      @Begin(join = true)   
      public String confirm()    
      {        
         return "confirmed";    
      }
      







        • 1. Re: Unintentional Entity Update when changing form
          bemar

          No ideas?

          • 2. Re: Unintentional Entity Update when changing form
            lvdberg

            Hi,


            This happens because you're using a managed bean inside your application. I can't see the rest of the code, but as soon as you start changing attributes, these chages will be persisted. To prevent this, switch to manual flushing and connect the final save/flush to the confirm button.


            You need to change some things:





            • Start the converation when you enter the properties page. You can add the manual flush in the page-definition in the begin tag, or as an attribute in the Begin-annotation.






            • Put the entitymanager.flush() in the confirm method and put the end-annotation also there.




            Hopefullly this helps




            Leo

            • 3. Re: Unintentional Entity Update when changing form
              bemar

              Hi,


              thx for your answer. Will try it asap and let you know.


              Best regards


              Ben

              • 4. Re: Unintentional Entity Update when changing form
                bemar
                Sorry, isn't working.

                I will describe my workflow:

                1. IncidentEdit.xhtml
                   EditPage. Inserting your values. BaseBean is incidentHome
                   Having
                `
                <begin-conversation join="true" flush-mode="MANUAL" />
                `
                in incidentEdit.page.xml

                `
                <h:commandButton id="view"
                value="#{messages.text_view}" action="#{incidentHome.confirm}" />
                `

                2.  incidentHome.confirm

                `
                @Begin(join = true)  
                public String confirm()   
                {       
                   return "confirmed";   
                }
                `
                3. page redirection to incident.xhtml via incidentEdit.page.xml

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

                        <!--  <action execute="#{incidentHome.wire}"/>-->

                        <param name="incidentFrom" />
                        <param name="incidentIdIncident" value="#{incidentHome.incidentIdIncident}" />


                        <navigation from-action="#{incidentHome.confirm}">
                                <rule if-outcome="confirmed">
                                        <redirect view-id="/Incident.xhtml" />
                                </rule>
                        </navigation>"


                When I debug into incidentHome.confirm button the update will right executed after leaving the method.

                I have the debug information on all of my xhtml sites on the conversion will be displayed as long-running. After the update the conversiation ID is still the same and the conversation is still long-running.




                • 5. Re: Unintentional Entity Update when changing form
                  kragoth
                  @Begin(join = true)
                  public String confirm()
                  {
                     return "confirmed";
                  }
                  



                  I think you need to reread what Leo wrote.





                  • Start the converation when you enter the properties page. You can add the manual flush in the page-definition in the begin tag, or as an attribute in the Begin-annotation.




                  • Put the entitymanager.flush() in the confirm method and put the end-annotation also there.





                  You do not want @Begin on the confirm method. You are ALREADY in a long running conversation. You possibly want an @End but certainly not @Begin.


                  I do my conversation management a very different way these days so I'm not as knowledgeable as Leo in this area so, read what he said carefully.