Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid not updating its XML Datasource

    Hello,

    I have a ListGrid populated through a client-only DS. Data loads fine, updates made through the ListGrid are displayed, but the values are not updated in the XML data file linked to the DS.

    I tried using:

    Code:
    nestedGrid.setAutoSaveEdits(true);
    and also the same kind of "save" button as shown in the showcase.

    Code:
                    IButton saveButton = new IButton("Save");
                    saveButton.setTop(250);
                    saveButton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            nestedGrid.saveAllEdits();
                        }
                    });
                    hLayout.addMember(saveButton);
    With both solutions, the edits seem to go through and are displayed, but nothing changes in the XML file.


    So here is what I am wondering:

    1. Are client-only DSs supposed to be able to save data?
    2. What I am doing wrong? The code for my DS is below.

    I am in dev-mode, using Jetty in the IntelliJ IDEA editor.


    Code:
    package gov.nist.toolkit.xdstools3.client.customWidgets.endpoints.configure;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    
    /**
     * SmartGWT datasource.
     *
     * Field names must match the XML source and must be unique to this datasource.
     */
    public class TransactionDS extends DataSource {
    
        private static TransactionDS instance = null;
    
        public static TransactionDS getInstance() {
            if (instance == null) {
                instance = new TransactionDS();
            }
            return instance;
        }
    
        private TransactionDS() {
            setID("transactionDS");
            setDataURL("resources/datasources/endpoints/pub-edited-2.data.xml");
            setRecordXPath("/site/actor/transaction"); //the XML path of the element we want to display, in the datasource file (.data.xml)
            setClientOnly(true);
    
            //---- actors ----
    
            DataSourceTextField siteName = new DataSourceTextField("siteName", "Site Name");
            siteName.setValueXPath("ancestor::site/@siteName");
            siteName.setHidden(true);
            siteName.setForeignKey("endpointConfigDSNew.endpointName");
    
            DataSourceTextField actorCode = new DataSourceTextField("actorCode", "Endpoint Code");
            actorCode.setValueXPath("parent::actor/@actorCode");
            actorCode.setDisplayField("actorName");
            actorCode.setHidden(true); // is already displayed in group mode title
    
            DataSourceTextField actorName = new DataSourceTextField("actorName");
            actorName.setValueXPath("parent::actor/@actorName");
            actorName.setHidden(true); // used only for formatting
    
    
            //---- transactions -----
    
            DataSourceTextField transactionCode = new DataSourceTextField("transactionCode");
            transactionCode.setPrimaryKey(true);
            transactionCode.setCanEdit(false); // primary keys cannot be edited. A workaround is to delete the record and create a new one with the same values.
            transactionCode.setDisplayField("transactionName");
    
            DataSourceTextField transactionName = new DataSourceTextField("transactionName", "Transaction Type");
            transactionName.setCanEdit(false);
            transactionName.setHidden(true); // used only for formatting
    
            DataSourceTextField tls = new DataSourceTextField("secure", "TLS Endpoint");
            DataSourceTextField notls = new DataSourceTextField("unsecure", "Non-TLS Endpoint");
    
    
            setFields(siteName, actorCode, actorName, transactionCode, transactionName, tls, notls);
        }
    }

    #2
    Client-only DataSources save changes for the lifetime of the page.

    They do not write to the filesystem to change the XML file from which data was loaded.

    Comment


      #3
      Thank you for the answer, that does indeed explain a lot! :)

      Any advice on the best strategies to save to file?
      Last edited by darkane; 17 Jul 2014, 10:10.

      Comment


        #4
        Hi darkane,

        do you want to download/export data with the user's browser or do you want to persist changes until the next use of your application?

        Do you need a specific file format?

        Which version of SmartGWT are you using? LGPL or PRO/POWER/ENTERPRISE (with server component)?

        Best regards,
        Blama

        Comment


          #5
          Hi Blama,

          I want to persist changes until the next use of the application, although I am not looking to do database persistence but rather save to an XML file as it is what I am using.

          I am using the LGPL version 4.1p.

          I found the exportData() function for a datasource, including setExportToFilesystem(true) and setExportAs(ExportFormat.XML)) and will try to export using these. They do seem like a server-side functionality though...

          Thank you.
          Last edited by darkane; 17 Jul 2014, 12:15.

          Comment

          Working...
          X