Announcement

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

    BatchUploader and customValidation

    Hi Isomorphic,

    Setup: SmartClient Version: v12.0p_2019-11-25/PowerEdition Deployment (built 2019-11-25)

    please see this testcase:


    BuiltInDS.java
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.PartialCommitOption;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.BatchUploader;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VStack;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class BuiltInDS implements EntryPoint {
    
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            VStack vStack = new VStack();
            vStack.setLeft(175);
            vStack.setTop(75);
            vStack.setWidth("70%");
            vStack.setMembersMargin(20);
    
            BatchUploader batchUploader = new BatchUploader();
            batchUploader.setUploadDataSource(DataSource.get("animals"));
            batchUploader.setPartialCommit(PartialCommitOption.RETAIN);
            batchUploader.setUploadDelimiter(";");
            ListGridField commonName = new ListGridField("commonName");
            ListGridField scientificName = new ListGridField("scientificName");
            batchUploader.setGridFields(commonName, scientificName);
    
            batchUploader.draw();
        }
    }
    BuiltInDS.html
    Code:
    <!DOCTYPE html>
    
    <html>
      <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <!--                                           -->
        <!-- Any title is fine                         -->
        <!--                                           -->
        <title>BuiltInDS</title>
    
        <!-- IMPORTANT : You must set the variable isomorphicDir to [MODULE_NAME]/sc/ so that the SmartGWT resource are 
          correctly resolved -->    
        <script> var isomorphicDir = "builtinds/sc/"; </script>
    
        <!--                                           -->
        <!-- This script loads your compiled module.   -->
        <!-- If you add any GWT meta tags, they must   -->
        <!-- be added before this line.                -->
        <!--                                           -->      
        <script type="text/javascript" language="javascript" src="builtinds/builtinds.nocache.js"></script>
    
        <!-- The following script is required if you're running (Super)DevMode and are using module
             definitions that contain <script> tags.  Normally, this script is loaded automatically
             by builtinds.nocache.js above, but this isn't possible when (Super)DevMode is running.
             Note: it should not create any issue to always load it below (even if already loaded). -->
        <script type="text/javascript" language="javascript" src="builtinds/loadScriptTagFiles.js"></script>
    
      </head>
    
      <!--                                           -->
      <!-- The body can have arbitrary html, or      -->
      <!-- you can leave the body empty if you want  -->
      <!-- to create a completely dynamic UI.        -->
      <!--                                           -->
      <body>
    
        <!--load the datasources-->
        <script src="builtinds/sc/DataSourceLoader?dataSource=supplyItem,animals,employees,batchUpload"></script>
    
        <!-- OPTIONAL: include this if you want history support -->
        <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
    
      </body>
    </html>
    animals.ds.xml
    Code:
    <DataSource
        ID="animals"
        serverType="sql"
        tableName="animals"
        testFileName="animals.data.xml"
    >
        <fields>
            <field name="commonName"      title="Animal"             type="text" >
                      <validators>
                <validator type="serverCustom">
                    <serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.CustomValidator" />
                        <errorMessage>$errorMessage</errorMessage>
                </validator>
            </validators>
         </field>
            <field name="scientificName"  title="Scientific Name"    type="text"  primaryKey="true"  required="true"/>
            <field name="lifeSpan"        title="Life Span"          type="integer"/>
            <field name="status"          title="Endangered Status"  type="text">
                <valueMap>
                    <value>Threatened</value>
                    <value>Endangered</value>
                    <value>Not Endangered</value>
                    <value>Not currently listed</value>
                    <value>May become threatened</value>
                    <value>Protected</value>
                </valueMap>
            </field>
            <field name="diet"            title="Diet"               type="text"/>
            <field name="information"     title="Interesting Facts"  type="text"  length="1000"/>
            <field name="picture"         title="Picture"            type="image" detail="true"
                   imageURLPrefix="/isomorphic/system/reference/inlineExamples/tiles/images/"/>
    
    
        </fields>
    </DataSource>

    batchUpload.ds.xml
    Code:
    <DataSource ID="batchUpload">
        <operationBindings>
            <operationBinding operationType="add" operationId="upload" serverMethod="batchUpload">
                <explanation>First do: boolean conversions, date conversions and list conversions. Then validate and upload data.</explanation>
            </operationBinding>
        </operationBindings>
        <serverObject ID="batchUpload" className="com.smartgwt.sample.server.listener.BatchUploadDMI" dropExtraFields="false">
            <visibleMethods>
                <method name="batchUpload" />
                <method name="wipeData" />
            </visibleMethods>
        </serverObject>
    </DataSource>

    BatchUploadDMI.java
    Code:
    package com.smartgwt.sample.server.listener;
    
    import java.util.Map;
    
    import com.isomorphic.datasource.DSRequest;
    import com.isomorphic.datasource.DSResponse;
    import com.isomorphic.tools.BatchUpload;
    
    public class BatchUploadDMI {
    
        public DSResponse batchUpload(DSRequest dsRequest) throws Exception {
            BatchUpload batchUpload = new BatchUpload();
    
            // parse data and get the result Map
            DSResponse response = batchUpload.parseUploadData(dsRequest);
            Map<?, ?> respData = response.getDataMap();
    
            // do not proceed to validation if parsing failed
            if (respData.containsKey("errorMessage"))
                return response;
    
            DSResponse validatedData = batchUpload.validateUploadData(response);
            return validatedData;
        }
    }

    CustomValidator.java
    Code:
    package com.smartgwt.sample.server.listener;
    
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.isomorphic.datasource.DataSource;
    import com.isomorphic.datasource.ValidationContext;
    import com.isomorphic.datasource.Validator;
    import com.isomorphic.log.Logger;
    
    public class CustomValidator {
    
        Logger log = new Logger(CustomValidator.class.getName());
    
        /**
         * @param value
         *          {@link Object}
         * @param validator
         *          {@link Validator}
         * @param fieldName
         *          {@link String}
         * @param record
         *          {@link Map}
         * @param ds
         *          {@link DataSource}
         * @param httpServletRequest
         *          {@link HttpServletRequest}
         * @return {@link Boolean}
         * @throws Exception
         */
        public boolean condition(Object value, Validator validator, String fieldName, Map<Object, Object> record, DataSource ds,
                HttpServletRequest httpServletRequest, ValidationContext context) throws Exception {
            log.info("Validating for field \"" + fieldName + "\", value \"" + (value == null ? "" : value.toString()) + "\"");
            context.setResultingValue("RESULTINGVALUE");
    
            return true;
        }
    }
    animals.csv
    Code:
    commonName;scientificName
    animal1;t
    animal2;z
    animal3;u
    What I expect that code should do:

    First click on search and select the "animals.csv", and click upload. I would have expected that in the "Preview-Grid" the value of "commonName" in any row has the value "RESULTINGVALUE" due to the "CustomValidator"(And it indeed gets hit on "upload"-click).
    But the values are still the same as in the "animals.csv".
    If You click "commit", the values change to "RESULTINGVALUE".

    What I need is that the resulting value is already set on "upload" and modify it on the client within:

    Code:
    batchUploader.addPreviewShownHandler(new PreviewShownHandler() {
    
                    @Override
                    public void onPreviewShown(PreviewShownEvent event) {
                });
    
            }
    and not on "commit".
    I need that because I want to show different icons (on a fake field/ not implemented here) in order of the validation result without triggering a validation error. And the logic that calculates the icon is done on the server and can not be moved to the client.

    Can You help me here to get this done?

    Thanks in Advance,
    Kind Regards






    #2
    Hi Isomorphic,

    are there any news about this topic? Its kind of urgent to get an answer here.

    Thanks in advance,
    Kind Regards

    Comment


      #3
      Sorry for the silence on this one - we have a developer taking a look and will respond when we have an answer for you

      Regards
      Isomorphic Software

      Comment


        #4
        It's been a few days, so this just another quick status update to reassure you that this is actively being worked on on our end.
        We'll follow up when we have more information for you

        Regards
        Isomorphic Software

        Comment


          #5
          Ok, thank you for the update.

          Regards

          Comment

          Working...
          X