Announcement Announcement Module
Collapse
No announcement yet.
How to restore the original data in a Form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to restore the original data in a Form

    Hello,

    I have a AbstractActionCommandExecutor that contains a TitledPageAplicationDialog that present a 'complex' object (with combos, lists, text fields...).
    When the 'onFinish()' method of TitledPageAplicationDialog is executed I try to update my object in a remote server. This works fine!
    The problem is when my server returns some expected error (like a business error) and my 'onFinish()' method return false. At this point the dialog window keeps on top, it's ok, but the internal properties values of my object is different than the values presented in the dialog.
    How can I revert the properties of my object (or some of it's properties - like the values of it's list and combos) to original values?
    I tried to revert the form, replace the form with a new form, update the form object but nothing do what I need.
    Can someone help me?

    Above is some code:

    Code:
        protected class ItineraryPropertiesCommandExecutor extends
            AbstractActionCommandExecutor
        {
            private SwingFormModel itineraryFormModel;
    
            private ItineraryGeneralForm itineraryForm;
    
            private FormBackedDialogPage dialogPage;
    
            /**
             * 
             */
            public ItineraryPropertiesCommandExecutor()
            {
                super();
            }
    
            /**
             * @see org.springframework.richclient.command.support.AbstractActionCommandExecutor#execute()
             */
            public void execute()
            {
                final ItineraryVO originalItinerary = new ItineraryVO();
                final ItineraryVO itinerary = new ItineraryVO();
                try
                {
                    VOUtils.copyProperties(originalItinerary, getSelectedObject());
                    VOUtils.copyProperties(itinerary, originalItinerary);
                }
                catch (WplexError e)
                {
                    JOptionPane.showMessageDialog(this.elementsTable, message);
                    return;
                }
    
                this.itineraryFormModel = SwingFormModel.createFormModel(itinerary);
    
                this.itineraryForm = new ItineraryGeneralForm(
                    this.itineraryFormModel);
    
                this.dialogPage = new FormBackedDialogPage(this.itineraryForm,
                    false);
    
                TitledPageApplicationDialog dialog = new TitledPageApplicationDialog(
                    this.dialogPage, getWindowControl())
                {
                    protected void onAboutToShow()
                    {
                        setEnabled(ItineraryPropertiesCommandExecutor.this.dialogPage
                            .isPageComplete());
                    }
    
                    protected boolean onFinish()
                    {
                        ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                            .commit();
                        try
                        {
                            ItineraryVO newItinerary = (ItineraryVO) ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                .getFormObject();
    
                            //myServer.updateMyObject(newItinerary);
                        }
                        catch (WplexError e)
                        {
                            JOptionPane.showMessageDialog(this.elementsTable, message);
    
    //TODO Here the values inside fields should be reverted to original values.
    
    /* this don't do what I nedd
                            ItineraryPropertiesCommandExecutor.this.itineraryFormModel = SwingFormModel
                                .createFormModel(orItinerary);
                            ItineraryPropertiesCommandExecutor.this.itineraryForm = new ItineraryGeneralForm(
                                ItineraryPropertiesCommandExecutor.this.itineraryFormModel);
                            ItineraryPropertiesCommandExecutor.this.dialogPage = new FormBackedDialogPage(
                                ItineraryPropertiesCommandExecutor.this.itineraryForm,
                                false);
                            ItineraryPropertiesCommandExecutor.this.itineraryForm.revert();
                            this.dispose();
                            this.showDialog();
    */
                            return false;
                        }
                        updateTable();
                        return true;
                    }
    
                };
                dialog.setTitle(getMessage("confirmUpdateItineraryDialog.title")); //$NON-NLS-1$
                dialog.showDialog();
            }
        }

  • #2
    I tried to revert the form
    revert() will revert the form back to the state it held at the last commit or the last time the backing object was changed. You commit the form in your onFinish() method so a later call to revert() will simply bring the form back to it's state at the start of the onFinish() method which obvoiusly includes all the edits. Make sence?

    replace the form with a new form
    This is not supported - if you want to change the form you'll have to replace the dialog as well. Unfotunatly this is not documented but the dialog caches the form internaly so changes to the form once it's been cached don't show up. So the reason you don't see any changes is bacuse you're still seeeing the original form.

    update the form object
    This is exactly what you should be doing so I'm not sure why it's not working... If you have nested form objects you could be getting caught out this bug http://opensource.atlassian.com/proj.../browse/RCP-57. I would expect the code in the error handling catch block would look something like this.

    Code:
    ...
                        }
                        catch (WplexError e)
                        {
                            JOptionPane.showMessageDialog(this.elementsTable, message);
    
                            ItineraryVO itinerary = new ItineraryVO();
                            VOUtils.copyProperties(itinerary, originalItinerary); 
                            itineraryFormModel.setFormObject(itinerary);
    
                            return false;
                        }
    HTH

    Ollie

    Comment


    • #3
      Note my example code if for the catch block in the onFinish() method.

      Comment


      • #4
        Ollie,

        First, many thanks for your attention!

        Originally posted by oliverhutchison
        revert() will revert the form back to the state it held at the last commit or the last time the backing object was changed. You commit the form in your onFinish() method so a later call to revert() will simply bring the form back to it's state at the start of the onFinish() method which obvoiusly includes all the edits. Make sence?
        Now I understood, thanks!

        Originally posted by oliverhutchison
        This is not supported - if you want to change the form you'll have to replace the dialog as well. Unfotunatly this is not documented but the dialog caches the form internaly so changes to the form once it's been cached don't show up. So the reason you don't see any changes is bacuse you're still seeeing the original form.

        This is exactly what you should be doing so I'm not sure why it's not working... If you have nested form objects you could be getting caught out this bug http://opensource.atlassian.com/proj.../browse/RCP-57.
        I'm a bit confuse: Even if I set a new object I still seeing the original form? This make sense? Or if I update the form object I should see the new form?

        BTW, I remain with the same problem!

        Dominique (dvienne) sent the spring-sandbox patch to me and my workspace is synchronized with spring-rich-c CVS HEAD.
        I've applied the RCP-57 patch and did exactly what you say, but the problem keeps the same. I also run the NestedPropertyTest but an error happens:

        Code:
        junit.framework.AssertionFailedError: expected: 'B' but was: 'E'
        Maybe I did some mistake applying the patch, specially with DefaultFormModel.java.patch, that have 2 versions. I've applied the file attachment DefaultFormModel.java.patch number 3, that is right? I hope this is the problem, but if isn't below is my full form code.
        The behavior of my components are very strange, for example, after I set the form object the property 'line' doesn't assign the new value but the property 'vehicleStationOrigin' assign the new value internally but not in the Dialog. Some idea?
        Please, see createLineField() and createVehicleStationField(...)

        Again, many thanks!

        Code:
            protected class ItineraryPropertiesCommandExecutor extends
                AbstractActionCommandExecutor
            {
                private SwingFormModel itineraryFormModel;
        
                private ItineraryGeneralForm itineraryForm;
        
                private FormBackedDialogPage dialogPage;
        
                /**
                 * 
                 */
                public ItineraryPropertiesCommandExecutor()
                {
                    super();
                }
        
                /**
                 * @see org.springframework.richclient.command.support.AbstractActionCommandExecutor#execute()
                 */
                public void execute()
                {
                    final ItineraryVO orItinerary = new ItineraryVO();
                    final ItineraryVO itinerary = new ItineraryVO();
                    try
                    {
                        VOUtils.copyProperties(orItinerary, getSelectedObject());
                        VOUtils.copyProperties(itinerary, orItinerary);
                    }
                    catch (WplexError e)
                    {
                        showMessageDialog(e.getMessage());
                        return;
                    }
                    final VehicleStationVO vehicleStationOrigin = (VehicleStationVO) itinerary
                        .getVehicleStationOrigin();
                    final VehicleStationVO vehicleStationDestiny = (VehicleStationVO) itinerary
                        .getVehicleStationOrigin();
                    final List nodes = itinerary.getNodes();
        
                    this.itineraryFormModel = SwingFormModel.createFormModel(itinerary);
                    this.itineraryForm = new ItineraryGeneralForm(
                        this.itineraryFormModel);
        
                    this.dialogPage = new FormBackedDialogPage(this.itineraryForm,
                        false);
        
                    TitledPageApplicationDialog dialog = new TitledPageApplicationDialog(
                        this.dialogPage, getWindowControl())
                    {
                        protected void onAboutToShow()
                        {
                            setEnabled(ItineraryPropertiesCommandExecutor.this.dialogPage
                                .isPageComplete());
                        }
        
                        protected boolean onFinish()
                        {
                            ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                .commit();
                            List itineraries = new ArrayList();
                            try
                            {
                                ItineraryVO newItinerary = (ItineraryVO) ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                    .getFormObject();
                                VehicleStationVO newVehicleStationOrigin = (VehicleStationVO) newItinerary
                                    .getVehicleStationOrigin();
                                VehicleStationVO newVehicleStationDestiny = (VehicleStationVO) newItinerary
                                    .getVehicleStationDestiny();
                                LinkedList newNodes = new LinkedList(newItinerary
                                    .getNodes());
                                newItinerary.setNodes(nodes);
                                newItinerary
                                    .setVehicleStationOrigin(vehicleStationOrigin);
                                newItinerary
                                    .setVehicleStationDestiny(vehicleStationDestiny);
        
                                ItineraryManagerView.this.delegate.updateItinerary(
                                    itinerary, newVehicleStationOrigin,
                                    newVehicleStationDestiny, newNodes);
                                /* 
                                 * REMARK O abaixo seria o correto, porém redesenhar
                                 * toda tabela após cada criação pode ser muito custoso,
                                 * então estou atualizando a tabela na mão.
                                 * Atualizar desta forma é uma estratégia perigosa pois
                                 * caso a estrutura da tabela alterar podemos ter 
                                 * problemas no seu redesenho. Porém isso é mais interessante
                                 * neste momento pois economizará um caminhão de tempo
                                 * de processamento.
                                 */
                                //updateTableData(newItinerary);
                            }
                            catch (WplexError e)
                            {
                                showMessageDialog(e.getMessage());
                                ItineraryVO newItinerary = new ItineraryVO();
                                try
                                {
                                    VOUtils.copyProperties(newItinerary, orItinerary);
                                }
                                catch (WplexError e1)
                                {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                                ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                    .setFormObject(newItinerary);
                                return false;
                            }
                            try
                            {
                                itineraries = new ArrayList(
                                    ItineraryManagerView.this.queryDelegate
                                        .findItineraries());
                            }
                            catch (WplexError e)
                            {
                                //TODO apresentar? showMessageDialog(e.getMessage());
                                return false;
                            }
                            ItineraryManagerView.this.elementsTableModel.clear();
                            ItineraryManagerView.this.elementsTableModel
                                .addRows(itineraries);
                            disableCommands();
                            return true;
                        }
                    };
                    dialog.setTitle(getMessage("confirmUpdateItineraryDialog.title")); //$NON-NLS-1$
                    //dialog.setDescription("Descrição");
                    dialog.showDialog();
                }
            }
        Code:
        /*
         * $Id: ItineraryGeneralForm.java,v 1.1 2005/03/30 15:03:14 mauro Exp $
         * 
         * Copyright (c) 2004-2005 Wplex Software Ltda. All rights reserved.
         */
        
        package com.wplex.common.client.ui.itinerary;
        
        import java.awt.Dimension;
        import java.util.ArrayList;
        import java.util.Collection;
        import java.util.Iterator;
        import java.util.List;
        
        import javax.swing.JComboBox;
        import javax.swing.JComponent;
        import javax.swing.JList;
        import javax.swing.JScrollPane;
        
        import org.springframework.binding.form.FormModel;
        import org.springframework.binding.value.ValueChangeListener;
        import org.springframework.binding.value.support.ValueHolder;
        import org.springframework.richclient.application.Application;
        import org.springframework.richclient.command.ActionCommand;
        import org.springframework.richclient.forms.AbstractForm;
        import org.springframework.richclient.list.BeanPropertyValueListRenderer;
        import org.springframework.richclient.list.ObservableList;
        
        import com.jgoodies.forms.builder.ButtonStackBuilder;
        import com.jgoodies.forms.layout.FormLayout;
        import com.wplex.common.business.interfaces.IItinerary;
        import com.wplex.common.business.vo.NodeVO;
        import com.wplex.common.client.delegate.CommonQueryDelegate;
        import com.wplex.common.client.struct.CodeNameStruct;
        import com.wplex.common.client.ui.WplexCommonFormBuilder;
        import com.wplex.common.client.ui.nodes.SelectNodesDialog;
        import com.wplex.common.client.util.GuiUtils;
        import com.wplex.framework.error.WplexError;
        
        /**
         * @author Mauro Ransolin
         * @version $Revision: 1.1 $
         *
         * TODO DOCU
         */
        public class ItineraryGeneralForm extends AbstractForm
        {
            /**
             * Nome do formulário para lookup pelo Spring.
             */
            public static final String ITINERARY_FORM_PAGE = "itineraryGeneralPage"; //$NON-NLS-1$
        
            protected final CommonQueryDelegate delegate = CommonQueryDelegate
                .getInstance();
        
            private JList jlNodes;
        
            private final ActionCommand addNodesCommand = new AddNodesCommand(
                "addNodesCommand"); //$NON-NLS-1$
        
            private final ActionCommand removeNodesCommand = new RemoveNodesCommand(
                "removeNodesCommand"); //$NON-NLS-1$
        
            /**
             * @param formModel
             */
            public ItineraryGeneralForm(FormModel formModel)
            {
                super(formModel, ITINERARY_FORM_PAGE);
            }
        
            /**
             * @see org.springframework.richclient.forms.AbstractForm#createFormControl()
             */
            protected JComponent createFormControl()
            {
                getObjectConfigurer().configure(this, ITINERARY_FORM_PAGE);
                FormLayout layout = new FormLayout("left:pref, 5dlu, pref:grow");
                WplexCommonFormBuilder formBuilder = new WplexCommonFormBuilder(
                    getFormModel(), layout);
        
                formBuilder.add("line", createLineField()); //$NON-NLS-1$
                formBuilder.add("kind", createKindField()); //$NON-NLS-1$
                formBuilder.add("direction", createDirectionField()); //$NON-NLS-1$
        
                formBuilder.appendSeparator("Nós e Terminais");
        
                //REMARK: A partir deste ponto poderia estar em uma página separada.
                formBuilder.add("vehicleStationOrigin", //$NON-NLS-1$
                    createVehicleStationField("vehicleStationOrigin")); //$NON-NLS-1$
        
                formBuilder.add("nodes", proceedNodesFieldCreation()); //$NON-NLS-1$
        
                formBuilder.add("vehicleStationDestiny", //$NON-NLS-1$
                    createVehicleStationField("vehicleStationDestiny")); //$NON-NLS-1$
        
                return formBuilder.getForm();
            }
        
            /**
             * @return JComponent
             */
            private JComponent proceedNodesFieldCreation()
            {
                Application.services().getCommandConfigurer().configure(
                    this.addNodesCommand);
                Application.services().getCommandConfigurer().configure(
                    this.removeNodesCommand);
                this.jlNodes = getFormModel().createBoundList("nodes");//$NON-NLS-1$
                this.jlNodes.clearSelection();//getModel().
                this.jlNodes.setCellRenderer(new BeanPropertyValueListRenderer("code")); //$NON-NLS-1$
        //        getObservableList().clear();
        //        getObservableList().addAll()
                return buildListControl();
            }
        
            /**
             * @return JComponent
             */
            private JComponent buildListControl()
            {
                ButtonStackBuilder builder = new ButtonStackBuilder();
                builder.addGridded(this.addNodesCommand.createButton());
                builder.addRelatedGap();
                builder.addGridded(this.removeNodesCommand.createButton());
                JScrollPane pane = new JScrollPane(this.jlNodes);
                pane.setPreferredSize(new Dimension(200, 100));
                JComponent buildListControl = GuiUtils.wrap(builder.getPanel(), pane);
                return buildListControl;
            }
        
            /**
             * @param propertyName
             * @return jcbVehicleStation
             */
            private JComponent createVehicleStationField(String propertyName)
            {
                ValueHolder vehicleStationHolder = null;
                try
                {
                    vehicleStationHolder = new ValueHolder(this.delegate
                        .findVehicleStations());
                }
                catch (WplexError e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        
                getFormModel().addFormObjectChangeListener(
                    new ItineraryVehicleStations(this, vehicleStationHolder));
        
                JComboBox jcbVehicleStation = getFormModel().createBoundComboBox(
                    propertyName, vehicleStationHolder, "code"); //$NON-NLS-1$
        
        
                return jcbVehicleStation; //apenas para ser mais explicito.
            }
        
            /**
             * @return jcbDirection
             */
            private JComponent createDirectionField()
            {
                getFormModel().createFormValueModel("direction"); //$NON-NLS-1$
        
                List structs = new ArrayList();
                for &#40;int i = 1; i < IItinerary.ITINERARY_DIRECTION_NAMES.length; i++&#41;
                &#123;
                    CodeNameStruct struct = new CodeNameStruct&#40;&#41;;
                    struct.setCode&#40;new Short&#40;&#40;short&#41; i&#41;&#41;;
                    struct.setName&#40;IItinerary.ITINERARY_DIRECTION_NAMES&#91;i&#93;&#41;;
                    structs.add&#40;struct&#41;;
                &#125;
        
                JComboBox jcbDirection = GuiUtils.createIdToIdComboBox&#40;getFormModel&#40;&#41;,
                    structs, "direction", //$NON-NLS-1$
                    "code", "name"&#41;; //$NON-NLS-1$ //$NON-NLS-2$
        
                return jcbDirection; //apenas para ser mais explicito.
            &#125;
        
            /**
             * @return jcbKind
             */
            private JComponent createKindField&#40;&#41;
            &#123;
                getFormModel&#40;&#41;.createFormValueModel&#40;"kind"&#41;; //$NON-NLS-1$
        
                List structs = new ArrayList&#40;&#41;;
                for &#40;int i = 1; i < IItinerary.ITINERARY_KIND_NAMES.length; i++&#41;
                &#123;
                    CodeNameStruct struct = new CodeNameStruct&#40;&#41;;
                    struct.setCode&#40;new Short&#40;&#40;short&#41; i&#41;&#41;;
                    struct.setName&#40;IItinerary.ITINERARY_KIND_NAMES&#91;i&#93;&#41;;
                    structs.add&#40;struct&#41;;
                &#125;
        
                JComboBox jcbKind = GuiUtils.createIdToIdComboBox&#40;getFormModel&#40;&#41;,
                    structs, "kind", //$NON-NLS-1$
                    "code", "name"&#41;; //$NON-NLS-1$ //$NON-NLS-2$
        
                return jcbKind; //apenas para ser mais explicito.
            &#125;
        
            /**
             * @return jcbLine
             */
            private JComponent createLineField&#40;&#41;
            &#123;
                ValueHolder linesHolder = null;
                try
                &#123;
                    linesHolder = new ValueHolder&#40;this.delegate.findLines&#40;&#41;&#41;;
                &#125;
                catch &#40;WplexError e&#41;
                &#123;
                    // TODO Auto-generated catch block
                    e.printStackTrace&#40;&#41;;
                &#125;
        
                getFormModel&#40;&#41;.addFormObjectChangeListener&#40;
                    new ItineraryLines&#40;this, linesHolder&#41;&#41;;
        
                JComboBox jcbLine = getFormModel&#40;&#41;.createBoundComboBox&#40;"line", //$NON-NLS-1$
                    linesHolder, "code"&#41;; //$NON-NLS-1$
        
                return jcbLine; //apenas para ser mais explicito.
            &#125;
        
            protected final ObservableList getObservableList&#40;&#41;
            &#123;
                return getFormModel&#40;&#41;.createBoundListModel&#40;"nodes"&#41;; //$NON-NLS-1$
            &#125;
        
            class ItineraryLines implements ValueChangeListener
            &#123;
                private final ValueHolder linesHolder;
        
                ItineraryLines&#40;ItineraryGeneralForm generalForm, ValueHolder linesHolder&#41;
                &#123;
                    this.linesHolder = linesHolder;
                &#125;
        
                /**
                 * @see org.springframework.binding.value.ValueChangeListener#valueChanged&#40;&#41;
                 */
                public void valueChanged&#40;&#41;
                &#123;
                    try
                    &#123;
                        this.linesHolder.setValue&#40;ItineraryGeneralForm.this.delegate
                            .findLines&#40;&#41;&#41;;
                    &#125;
                    catch &#40;WplexError e&#41;
                    &#123;
                        // TODO Auto-generated catch block
                        e.printStackTrace&#40;&#41;;
                    &#125;
                &#125;
        
            &#125;
        
            class ItineraryVehicleStations implements ValueChangeListener
            &#123;
                private final ValueHolder vehicleStationsHolder;
        
                ItineraryVehicleStations&#40;ItineraryGeneralForm generalForm,
                    ValueHolder vehicleStationsHolder&#41;
                &#123;
                    this.vehicleStationsHolder = vehicleStationsHolder;
                &#125;
        
                /**
                 * @see org.springframework.binding.value.ValueChangeListener#valueChanged&#40;&#41;
                 */
                public void valueChanged&#40;&#41;
                &#123;
                    try
                    &#123;
                        this.vehicleStationsHolder
                            .setValue&#40;ItineraryGeneralForm.this.delegate
                                .findVehicleStations&#40;&#41;&#41;;
                    &#125;
                    catch &#40;WplexError e&#41;
                    &#123;
                        // TODO Auto-generated catch block
                        e.printStackTrace&#40;&#41;;
                    &#125;
                &#125;
        
            &#125;
        
            class AddNodesCommand extends ActionCommand
            &#123;
        
                AddNodesCommand&#40;String commandId&#41;
                &#123;
                    super&#40;commandId&#41;;
                &#125;
        
                /**
                 * @see org.springframework.richclient.command.ActionCommand#doExecuteCommand&#40;&#41;
                 */
                public void doExecuteCommand&#40;&#41;
                &#123;
                    if &#40;this.dialog == null&#41;
                        this.dialog = new ItinerarySelectNodesDialog&#40;&#41;;
                    this.dialog.showDialog&#40;&#41;;
                &#125;
        
                private ItinerarySelectNodesDialog dialog;
            &#125;
        
            class ItinerarySelectNodesDialog extends SelectNodesDialog
            &#123;
                ItinerarySelectNodesDialog&#40;&#41;
                &#123;
                    super&#40;&#41;;
                &#125;
        
                /**
                 * Antes de apresentar, remove os nós que já foram selecionados pelo 
                 * usuário.
                 * TODO testar performance.
                 */
                protected void onAboutToShow&#40;&#41;
                &#123;
                    Collection usedNodes = getObservableList&#40;&#41;;
                    for &#40;Iterator iter = usedNodes.iterator&#40;&#41;; iter.hasNext&#40;&#41;;&#41;
                    &#123;
                        NodeVO node = &#40;NodeVO&#41; iter.next&#40;&#41;;
                        int rowPos = this.nodesTableModel.rowOf&#40;node&#41;;
                        if &#40;rowPos != -1&#41;
                            this.nodesTableModel.remove&#40;rowPos&#41;;
                    &#125;
                    
                    super.onAboutToShow&#40;&#41;;
                &#125;
                protected boolean onFinish&#40;&#41;
                &#123;
                    NodeVO node = getSelectedNode&#40;&#41;;
                    if &#40;node != null&#41;
                        getObservableList&#40;&#41;.add&#40;node&#41;;
                    return true;
                &#125;
            &#125;
        
            class RemoveNodesCommand extends ActionCommand
            &#123;
        
                RemoveNodesCommand&#40;String commandId&#41;
                &#123;
                    super&#40;commandId&#41;;
                &#125;
        
                /**
                 * @see org.springframework.richclient.command.ActionCommand#doExecuteCommand&#40;&#41;
                 */
                public void doExecuteCommand&#40;&#41;
                &#123;
                    if &#40;ItineraryGeneralForm.this.jlNodes.getSelectedIndex&#40;&#41; != -1&#41;
                        getObservableList&#40;&#41;.remove&#40;
                            ItineraryGeneralForm.this.jlNodes.getSelectedIndex&#40;&#41;&#41;;
                &#125;
            &#125;
        &#125;

        Comment


        • #5
          Problem solved!

          Hi Folks,

          5 minutes after I the previous post I solve my problem and discover some interesting:

          If I apply the code below, nothing happens in the Dialog

          Code:
          catch &#40;WplexError e&#41;
              &#123;
                  showMessageDialog&#40;e.getMessage&#40;&#41;&#41;;
                  ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                      .setFormObject&#40;orItinerary&#41;;
                  return false;
              &#125;
          But if I apply the code below, all data in my dialog are reseted by blank data.

          Code:
          catch &#40;WplexError e&#41;
          &#123;
              showMessageDialog&#40;e.getMessage&#40;&#41;&#41;;
              ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                  .setFormObject&#40;new ItineraryVO&#40;&#41;&#41;;
              return false;
          &#125;
          Why the difference? I don't know!



          To solve my problem I only need is to set my variable itinerary with the formObject

          Code:
          ItineraryPropertiesCommandExecutor.this.itinerary = &#40;ItineraryVO&#41; ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                      .getFormObject&#40;&#41;;
          and then set it's properties with the desired values:
          Code:
          ItineraryPropertiesCommandExecutor.this.itinerary
              .setNodes&#40;this.newNodes&#41;;
          ItineraryPropertiesCommandExecutor.this.itinerary
              .setVehicleStationOrigin&#40;this.newVehicleStationOrigin&#41;;
          ItineraryPropertiesCommandExecutor.this.itinerary
              .setVehicleStationDestiny&#40;this.newVehicleStationDestiny&#41;;
          The setFormObject was not necessary 'cause the containment is by reference, not by value.

          Below, the full working code:


          Thanks all!
          Code:
                          protected boolean onFinish&#40;&#41;
                          &#123;
                              ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                  .commit&#40;&#41;;
                              List itineraries = new ArrayList&#40;&#41;;
                              try
                              &#123;
                                  ItineraryPropertiesCommandExecutor.this.itinerary = &#40;ItineraryVO&#41; ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                                      .getFormObject&#40;&#41;;
                                  this.newVehicleStationOrigin = &#40;VehicleStationVO&#41; ItineraryPropertiesCommandExecutor.this.itinerary
                                      .getVehicleStationOrigin&#40;&#41;;
                                  this.newVehicleStationDestiny = &#40;VehicleStationVO&#41; ItineraryPropertiesCommandExecutor.this.itinerary
                                      .getVehicleStationDestiny&#40;&#41;;
                                  this.newNodes = new LinkedList&#40;
                                      ItineraryPropertiesCommandExecutor.this.itinerary
                                          .getNodes&#40;&#41;&#41;;
                                  ItineraryPropertiesCommandExecutor.this.itinerary
                                      .setNodes&#40;nodes&#41;;
                                  ItineraryPropertiesCommandExecutor.this.itinerary
                                      .setVehicleStationOrigin&#40;vehicleStationOrigin&#41;;
                                  ItineraryPropertiesCommandExecutor.this.itinerary
                                      .setVehicleStationDestiny&#40;vehicleStationDestiny&#41;;
          
                                  ItineraryManagerView.this.delegate.updateItinerary&#40;
                                      ItineraryPropertiesCommandExecutor.this.itinerary,
                                      this.newVehicleStationOrigin,
                                      this.newVehicleStationDestiny, this.newNodes&#41;;
                                  /* 
                                   * REMARK O abaixo seria o correto, porém redesenhar
                                   * toda tabela após cada criação pode ser muito custoso,
                                   * então estou atualizando a tabela na mão.
                                   * Atualizar desta forma é uma estratégia perigosa pois
                                   * caso a estrutura da tabela alterar podemos ter 
                                   * problemas no seu redesenho. Porém isso é mais interessante
                                   * neste momento pois economizará um caminhão de tempo
                                   * de processamento.
                                   */
                                  //updateTableData&#40;newItinerary&#41;;
                              &#125;
                              catch &#40;WplexError e&#41;
                              &#123;
                                  showMessageDialog&#40;e.getMessage&#40;&#41;&#41;;
                                  ItineraryPropertiesCommandExecutor.this.itinerary
                                      .setNodes&#40;this.newNodes&#41;;
                                  ItineraryPropertiesCommandExecutor.this.itinerary
                                      .setVehicleStationOrigin&#40;this.newVehicleStationOrigin&#41;;
                                  ItineraryPropertiesCommandExecutor.this.itinerary
                                      .setVehicleStationDestiny&#40;this.newVehicleStationDestiny&#41;;
          
                                  return false;
                              &#125;
                              try
                              &#123;
                                  itineraries = new ArrayList&#40;
                                      ItineraryManagerView.this.queryDelegate
                                          .findItineraries&#40;&#41;&#41;;
                              &#125;
                              catch &#40;WplexError e&#41;
                              &#123;
                                  //TODO apresentar? showMessageDialog&#40;e.getMessage&#40;&#41;&#41;;
                                  return false;
                              &#125;
                              ItineraryManagerView.this.elementsTableModel.clear&#40;&#41;;
                              ItineraryManagerView.this.elementsTableModel
                                  .addRows&#40;itineraries&#41;;
                              disableCommands&#40;&#41;;
                              return true;
                          &#125;

          Comment


          • #6
            Why the difference? I don't know!
            I suspect it's down to the way you've implemented ItineraryVO.equals() could you please post the code for that method?

            Also couldnt you just do the following to update the form model?

            Code:
            VOUtils.copyProperties&#40;itineraryFormModel.getFormObject&#40;&#41;, orItinerary&#41;;

            Ollie

            Comment


            • #7
              Also couldnt you just do the following to update the form model?

              Code:
              VOUtils.copyProperties&#40;itineraryFormModel.getFormObject&#40;&#41;, orItinerary&#41;;
              Ollie
              Yes, I could do the above, but like the Form doesn't display the original values (orItinerary) I prefer to keep showing the values fulfilled by the user.

              Originally posted by oliverhutchison
              Why the difference? I don't know!
              I suspect it's down to the way you've implemented ItineraryVO.equals() could you please post the code for that method?
              Excellent Ollie, you are wright! The form detect the object has changed, than clean the cache and update the form.
              The above restore the original values of the form:
              Code:
                  catch &#40;WplexError e&#41;
                  &#123;
                      showMessageDialog&#40;e.getMessage&#40;&#41;&#41;;
              
                      //ItineraryPropertiesCommandExecutor.this.itinerary
                      //.setNodes&#40;this.newNodes&#41;;
                      //ItineraryPropertiesCommandExecutor.this.itinerary
                      //.setVehicleStationOrigin&#40;this.newVehicleStationOrigin&#41;;
                      //ItineraryPropertiesCommandExecutor.this.itinerary
                      //.setVehicleStationDestiny&#40;this.newVehicleStationDestiny&#41;;
              
                      ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                          .setFormObject&#40;new ItineraryVO&#40;&#41;&#41;;
                      ItineraryPropertiesCommandExecutor.this.itineraryFormModel
                          .setFormObject&#40;orItinerary&#41;;
              
                      return false;
                  &#125;
              Folow the equals and hashCode
              Code:
                  /**
                   * @see java.lang.Object#equals&#40;java.lang.Object&#41;
                   */
                  public boolean equals&#40;Object object&#41;
                  &#123;
                      return object instanceof Serializable && equals&#40;&#40;ValueObject&#41; object&#41;;
                  &#125;
              
                  /**
                   * @param vo
                   * @return if equals
                   */
                  public boolean equals&#40;ValueObject vo&#41;
                  &#123;
                      return vo == null ? false &#58; &#40;vo.getId&#40;&#41; == null ? getId&#40;&#41; == null &#58; vo
                          .getId&#40;&#41;.equals&#40;getId&#40;&#41;&#41;&#41;;
                  &#125;
              
                  /**
                   * @see java.lang.Object#hashCode&#40;&#41;
                   */
                  public int hashCode&#40;&#41;
                  &#123;
                      return getId&#40;&#41; != null ? getId&#40;&#41;.intValue&#40;&#41; &#58; 0;
                  &#125;

              Comment

              Working...
              X