即使禁用,上传组件仍会在点击时打开对话框

时间:2012-08-16 09:46:30

标签: vaadin

我正在使用Vaadin框架开发Web应用程序。

我正在使用Vaadin上传组件。为方便起见,我们决定在文件上传到服务器时禁用上传按钮。

问题是该按钮看起来已禁用,但点击它时仍会打开文件浏览器对话框,让用户指定无法正确处理的其他文件。

在调试期间,我已停止在Upload progressListener内部,并看到Upload对象的 Enabled 参数设置为 false ,即使如此,如果我尝试单击禁用GUI中的按钮对话框将打开..

我已经尝试过搜索这是否是一个公认的错误但是找不到任何内容。

一些相关代码:

   //The first listener triggered when starting an upload, here the 
   // Upload component is set to disabled
    upload.addListener(new Upload.StartedListener() {
                public void uploadStarted(StartedEvent event) {
                    // this method gets called immediately after upload is started

                    upload.setEnabled(false);
    }

    // Listener being triggered a number of times during the upload. 
    // Here is where I debugged, saw that the Upload component was 
    // disabled but found that I still could open the dialogue. 
            upload.addListener(new Upload.ProgressListener() {
                public void updateProgress(long readBytes, long contentLength) {

    }

    // The last listener triggered, here the Upload component is 
    // set to enabled. The button now looks clickable but it behaves 
    // the same way as it does when the Upload component is disabled.
    upload.addListener(new Upload.FinishedListener() {
                public void uploadFinished(FinishedEvent event) {
                    if(uploadOk){
                        fileListItem.getProgressIndicator().stopPolling();
                        fileListItem.removeProgressIndicator();
                        fileListItem.removeAbortButton();
                        submitFilesBt.setEnabled(true);
                        removeFilesBt.setEnabled(true);
                        fileListItem.setFile(counter.getFile());
                        upload.setEnabled(true);                }
                }
            });

2 个答案:

答案 0 :(得分:0)

我从未设法解决组件的问题,但我通过将Upload组件放在专用容器中来解决问题。当我启动上传时,我从容器中删除了组件,而是插入了一个看起来相同且被禁用的虚拟替换按钮。上传完成后,我删除了虚拟按钮并再次添加了上传按钮。

使用这种方法可以避免这个问题,但如果有人认为这是解决问题的原因,我会同意......

答案 1 :(得分:0)

这显然是上传组件中的一个错误,您应该考虑在http://dev.vaadin.com/进行报告。

与此同时,AndroidHustle建议的解决方法可能是最简单的。另外,我建议将此解决方案打包到CustomComponent并继续编写应用程序的其余部分,并在修复程序可用时将实现切换回上载。

相关问题