我正在使用 Vaadin 框架开发一个 Web 应用程序。
我正在使用 Vaadin Upload 组件。为方便起见,我们决定在文件已上传到服务器时禁用上传按钮。
问题是该按钮看起来已禁用,但单击时仍会打开文件浏览器对话框,让用户指定无法正确处理的其他文件。
在调试期间,我已经在 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); }
}
});