简体   繁体   中英

How to use GWT fileupload?

I have some queries when trying to implement a fileupload widget in my application. After many tries, it just doesn't seem to work.

Hence, I tried getting working solutions to see if I can understand anything from there.

http://code.google.com/p/faculty-gwt/source/checkout

However, I tried uploading a file using this and it seems that I am getting error messages too. and what is that textbox and listbox suppose to do? It is meant for showing an example of validating an input before submitting?

Can someone guide me along to solve this? Thanks.

Never tried to use the link you provided, but this is what i did to use aa GWT FileUpload widget:

I built a File Upload widget using the uibinder:

<g:FormPanel ui:field="docForm">
    <g:FlowPanel ui:field="inputPane">
        /*other displayed info*/
        <g:FileUpload ui:field="DocPath"/>
        /*other displayed info*/
    </g:FlowPanel>
</g:FormPanel>

(Per the GWT api, FileUpload widgets can only be used from a FormPanel)

Make sure you set these in the FormPanel, otherwise you'll probably have issues:

    yourFormPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    yourFormPanel.setMethod(FormPanel.METHOD_POST);

That widget is dropped into my container page, then added to the display panel:

private FileUploadWidget createNewUploader(){
    FileUploadWidget uploader = new FileUploadWidget(/*my constructor params*/);

    uploader.addChangeHandler(new ChangeHandler() {         
        @Override
        public void onChange(ChangeEvent event) {
            DocPanel.add(createNewUploader());
        }
    });

    return uploader;
}

My OnChange event is so that I have a new, blank uploader available when i use the current one.

and when I'm ready to submit:

private void processUpload(FileUploadWidget upload, int id) {
    upload.setId(id);
    //Don't bother to submit an empty one.
    if (upload.IsFileSelected())
        upload.Submit();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM