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

时间:2015-05-13 02:38:34

标签: upload 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

如何禁用上传按钮?

1 个答案:

答案 0 :(得分:2)

我不知道如何禁用提交按钮,但您可以先隐藏它并在用户选择要上传的文件时进行呈现。

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

我希望这有帮助!