gwtgwt-platformgwtupload

gwtupload: Hidden values getting appended


I'm using SingleUploader for uploading a file. I have few hidden fields that I'm setting on start of upload. The upload works fine but when I upload again the old hidden values do not cleared. Instead the hidden values are getting appended. SingleUploader#clear() seems to work for clearing the values but it also removes the Send Button from the existing form.

getView().getUploader().addOnStartUploadHandler(new IUploader.OnStartUploaderHandler() {

        @Override
        public void onStart(IUploader uploader) {
            if(validateForm()){
                String val1 = getView().getFirstFieldTxtBx().getValue().trim();
                String val2 = getView().getStartDateBx().getValue().toString();
                String val3 = getView().getEndDateBx().getValue().toString();

                uploader.add(new Hidden("first",val1), 0);
                uploader.add(new Hidden("second",val2),1);
                uploader.add(new Hidden("third",val3),2);
            }else{
                uploader.cancel();
            }
        }
    });

How do I get rid of the existing hidden values? Or is there any other way to send the hidden values to the server using gwtupload?


Solution

  • Use isVisible() method to find out which components needs to be cleared. Iterate through all the children and based on there visibility clear the values.

    You can use instanceof Hidden to find out hidden components only while iterating all the children.

    Read more about List all the widgets of a page/panel in GWT