4 Replies Latest reply on Nov 30, 2009 10:41 AM by ohughes

    Simple Edit Page

    ohughes

      Hi,


      I need to write a simple edit page, where the user sees a list of what there is to edit, and then upon selection, the user can unlock the screen, and then either edit and save, or otherwise press cancel.
      What I am struggling with, is when the user decides to click on cancel, and he/she has removed some values from relationships.  How do I undo a users set of changes?  I have tried refresh, but the object that was set for deletion is still deleted from the database, but is available in the relationships.


      Anyone any thoughts or ideas around this problem?


      Here is some code to show you what I'm doing to get to this problem:




      @Name("ecuSearchColumns")
      @Scope(ScopeType.PAGE)
      public class SearchColumns extends NexusEntityHome<DataFormatSupportedIDS> implements ActionButtonListener {
      
        ...
      
           @Override
           public String processCancel() {
                unsynchronizeValuesForCancel();  //this method simply removes new items that the DB doesn't know about
                DataFormatSupportedIDS current = getInstance();
                clearInstance();
                getSession().refresh(current);
                for (ErrorSearchColumn srchCol : current.getErrorSearchColumns()) {
                     getSession().refresh(srchCol);
                     getSession().refresh(srchCol.getDataFormatSupportedIDS());
                     getSession().refresh(srchCol.getMetaField());
                }
                setSelectedItem((DataFormatSupportedIDS) getSession().get(DataFormatSupportedIDS.class, current.getId()));
                lockScreen();
                return super.processCancel();
           }
      
        ...
      
      }




      This seems like a big overhead, and possible cause for problems if we have to refresh each and every object that might have been touched.


      Is there no easy way to tell the Session to forget about any changes?


      Thanks,
      Osian

        • 1. Re: Simple Edit Page
          kapitanpetko

          Osian Hughes wrote on Nov 26, 2009 13:52:



          This seems like a big overhead, and possible cause for problems if we have to refresh each and every object that might have been touched.

          Is there no easy way to tell the Session to forget about any changes?



          Well, you could always call Session.clear(), it would forget everything :) Depending on your application, that might not be desirable, though: if you go back to the entity list page, for example, you'll have to reload from the DB, etc. Anyway, refresh() is convenient for implementing undo, but that is not what it is designed for. You could work with detached classes instead, that would make undo really easy (simply don't merge), but as we know has other disadvantages. So no easy solution for this, AFIK, you have to either clear everything or carefully reattach all associations.


          • 2. Re: Simple Edit Page
            ohughes

            Thanks for the reply.


            It seems strange that there is no easy solution for this!  With EOModeler you could always call revert on the session and all changes would be rolled back.
            Is it possible to have a different session created for the Home page? and then calling clear on this wouldn't impact on the main session?  or is this going down the wrong route??


            Thanks,
            Osian

            • 3. Re: Simple Edit Page
              kapitanpetko

              AFAIK (never used those), nested conversations where supposed to offer this, but there are a number of problems with those, so you better avoid them. You can always implement this yourself, but it's not supported out of the box. There are some ideas on the forum though.

              • 4. Re: Simple Edit Page
                ohughes

                I had the same thoughts with nested conversations, but I am still unable to get separate conversations running in my application.


                Any pointers on which posts I should look at for how to implement some kind of undo functionality?