Question

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?

Was it helpful?

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

OTHER TIPS

I came up with a workaround. I'm calling the clearFormFields method on finish and on cancel of upload.

private void clearFormFields(SingleUploader uploader) {
    removeWidget(((FlowPanel)uploader.getForm().getWidget()).getWidget(2));
    removeWidget(((FlowPanel)uploader.getForm().getWidget()).getWidget(1));
    removeWidget(((FlowPanel)uploader.getForm().getWidget()).getWidget(0));
}

private void removeWidget(Widget w) {
    if(w instanceof Hidden){
        w.removeFromParent();
    }
}

What you describe is a bug in the library, uploader.clear() should do the work, so as you dont have to do it by hand.

Feel free to open an issue and I would take care of fixing it in the next gwtupload release.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top