vaadin]在上传组件中,上传按钮时没有选中文件事件

我使用上传组件

资源 ..

    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 ;
        }
    });

我想禁用上传按钮 – 不是文件选择按钮.

当我单击文件选择按钮并没有选择文件时,
上传按钮禁用状态.

我试过upload.setButtonCaption(null),但Exeption … TT

如何禁用上传按钮?

最佳答案 我不知道如何禁用提交按钮,但您可以先隐藏它并在用户选择要上载的文件时进行渲染.

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");
    }
});

我希望这有帮助!

点赞