Vaadin] in the download component, click the "Download" button when the selected file is not selected

I am using the download component

source..

    upload = new Upload(" ",  new Upload.Receiver() {

        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {
            FileOutputStream fos = null ;
                if(filename.length() > 0){
                    try {
                        tempFile = File.createTempFile(filename, ".txt", new File("/home/nap/scroll/") ) ;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        fos = new FileOutputStream(tempFile) ;
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }else{
                    Notification.show(Messages.getString(Messages.Dialog_No_Selected_File),
                              "-",
                              Notification.Type.WARNING_MESSAGE);
                    portletUI.rePrint(request);
                    initListSelect();
                }
            return fos ;
        }
    });

I want to disable the download button, not the file select button.

When I pressed the file selection button and did not select the file, disable the download status.

I tried upload.setButtonCaption (null) but Exeption ... TT

How to disable the download button?

+4
source share
1 answer

I don’t know how you can disable the submit button, but first you can hide it and display it when the user selects the file to upload.

ImageUploader receiver = new ImageUploader();
Upload upload = new Upload("Upload", receiver);
upload.setButtonCaption(null);
upload.addChangeListener(new ChangeListener()
{
    @Override
    public void filenameChanged(ChangeEvent event)
    {
        if (event.getFilename() != null)
            upload.setButtonCaption("Lets go");
    }
});

Hope this helps!

+2
source

All Articles