Announcement

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

    Set hidden value in BatchUploader's Grid

    Hi,
    I am implementing batchUploader that uploads a CSV having fields name,type. It has client side validation on type field. The Grid gets populated with validation errors. Now my requirement is to provide a text box and a replace button to replace all the failed values with the correct one. When I iterated the list grid records for their attributes I get null for the failed cell values even if the value is visible on screen (with validation failed). So I am unable to proceed with replacing the records with the new value.

    So my question is how can I get the value of a validation failed cell ?

    Code:
    for (ListGridRecord record : batchUploader.getGrid().getRecords()) {
    for(String attr : record.getAttributes()){
    GWT.log(attr+" = "+record.getAttribute(attr)); //I always get null here for cells for which validation has failed.
    }
    I tried to take a hidden field in DS.xml to hold the value from "type" field, so that I can do the calculation based on the hidden field. I tried the below in DS.xml :
    Code:
    <field name="type" type="text" title="Type" length="128" />
    <field name="typeHidden" type="text" displayField="type"/>
    This also does not work because batchuploader is only considering the columns that are available in CSV file.

    Any suggestions on this? How should I read/get the value of a cell for which the validation has failed ,So that I can replace then with valid values?
    Thanks in advance.

    Regards,
    Preeti

    #2
    Please read the Grid Editing overview. The invalid values are editValues.

    Comment


      #3
      Thank Isomorphic for the response. I can now get the desired values using getEditValues(Record record) method. I am trying to send a parameter with all the "add" requests of queue. as provided in the batachuploader doucmentation.
      Code:
          Map prop= new HashMap<>();
              prop.put("myParameter", "myParam");
              batchUploader.setRequestProperties(requestProperties);
      In console I get the variable :
      Code:
      {
          dataSource:"myDS", 
          operationType:"add", 
          data:{
              //data here
          }, 
          textMatchStyle:"exact", 
          willHandleError:true, 
          showPrompt:true, 
          oldValues:{
              //old values
          }, 
          requestId:"myDS$6274", 
          fallbackToEval:false, 
          myParameter:"myParam", 
          lastClientEventThreadCode:"MUP5", 
          bypassCache:true, 
          dataProtocol:"getParams"
      }
      But I am not able to get this "myParameter" on my server code using dsRequest.getparameter() or dsRequest.getAttributes().


      I also tried "uploadFormFields" and tried httpSession.getAttribute() but Still not getting the parameter value.

      How can I send and get and additional parameter with all add requests on server?

      Thanks in advance.

      Comment


        #4
        uploadFormFields is the correct and well-documented way to do this. You’ve simply mentioned in passing that you couldn’t get this to work, but provided no details. We show this feature working as expected. Let us know if you can provide any information that would allow us to help.

        Comment


          #5
          Hi Isomorphic,

          I think the OP is talking about the 2nd commit and not the 1st upload (“queue add”). Does uploadFormFields also apply there?

          Best regards
          Blama

          Comment


            #6
            The OP’s descriptions are all over the place, as he’s referring to singular parameters at the same time as per-record values and oscillating back and forth between these two unrelated needs.

            He’s already been given solutions to both needs - uploadFormFields for singular, editValues for per-record.

            Comment


              #7
              Hi Blama , Isomorphic ,
              Yes, I am talking about the second commit operation. upoadFormFields are sent on the upload call not the second commit. I can go for setEditValues on grid for each row but I can't find any handler of commit button to set value. Even if I do something like this :
              Code:
                 batchUploader.getGrid().setEditValue(batchUploader.getGrid().getRecordIndex(record), "myID",
                                          "200");
              Above fails because on page load there is no grid available and that results in null pointer exception. I cant find any handler that runs just before the final commit. Kindly suggest.

              Comment


                #8
                Hi preeti_kanyal.

                if you know the resulting values at upload processing time, you could compute the values serverside and send them back with the upload result with a BatchUploadDMI.java, referenced from your batchUpload.ds.xml file.
                Otherwise, commitButton is an AutoChild, perhaps you can change the clickHandler there to do your precalculations client side.

                Best regards
                Blama

                Comment


                  #9
                  Hi Blama ,
                  I can't write the clickHandler of commitButton because this button is only visible when the file is uploaded. The documentation of setRequestProperties method says "Object containing properties to send with every "add" request this batchUploader sends." . This is my exact requirement. I did batchUploader.setRequestProperties(requestProperties) But I can't get them on server. Any way I can get the request properties on server? I attached the details in my comment #3.

                  Regards

                  Comment


                    #10
                    Hi preeti_kanyal,

                    OK, this seems like a bug to me, but I don't know that for sure. I find it strange that the type of the parameter of batchUploader.setRequestProperties(requestProperties) is java.util.Map.
                    In e.g. ListGrid.fetchData() the parameter named requestProperties is of type DSRequest. This might be wrong, but again I don't know this.

                    Best regards
                    Blama


                    Comment


                      #11
                      #1 setRequestProperties API is fixed.

                      #2 Please consider approaches shown below, which allow getting access to AutoChild components, like grid and commitButton of BatchUploader. Note these are not the only possibilities, just couple of samples.

                      Code:
                      // option 1
                      batchUploader.addPreviewShownHandler(new PreviewShownHandler() {
                              @Override
                              public void onPreviewShown(PreviewShownEvent event) {
                                      ListGrid lg = batchUploader.getGrid();
                                      lg.setEditValue(row, fieldName, value);
                                      lg.validateRow(row);
                              }
                      }); 
                      
                      
                      // option 2
                      batchUploader.addPreviewShownHandler(new PreviewShownHandler() {
                              @Override
                              public void onPreviewShown(PreviewShownEvent event) {
                                      batchUploader.getCommitButton().addMouseDownHandler(new MouseDownHandler() {
                                              @Override
                                              public void onMouseDown(MouseDownEvent event) {
                                                      ListGrid lg = batchUploader.getGrid();
                                                      lg.setEditValue(row, fieldName, value);
                                                      lg.validateRow(row);
                                              }
                                      });
                              }
                      });

                      Comment

                      Working...
                      X