我使用GXT File UploadField上传数据代码如下所示,但是当我点击上传按钮时,浏览器会第一次阻止上传弹出窗口。之后它正常工作。当我重新加载页面时,为什么弹出窗口第一次被阻止?我必须双击该按钮才能打开上传弹出窗口。
if (uploadFileView == null) {
uploadFileView = new UploadFileView();
/* upldate Labels */
uploadFileView.setHeading(uploadBasicLabels.uploadNewFile());
uploadFileView.getBtnSubmit().setText(uploadBasicLabels.upload());
uploadFileView.getBtnSubmit().addListener(Events.Select, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
String id = uploadFileView.getFileField().getFileInput().getId();
if(presenter.validateFile(id)){
resetAllowed = false;
uploadFileView.hide();
presenter.uploadNewFile();
}else
uploadFileView.getBtnSubmit().setEnabled(false);
}
});
uploadFileView.addListener(Events.Hide, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if(resetAllowed && !uploadFileView.isVisible()) {
presenter.validateClose();
// presenter.resetCurrentRow();
}
resetAllowed = true;
}
});
uploadFileView.getFileField().addListener(Events.OnChange, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if(uploadFileView.getFileField().getValue().equals("")){
uploadFileView.getBtnSubmit().setEnabled(false);
}else{
uploadFileView.getBtnSubmit().setEnabled(true);
/* on change Event Called twice */
if(timer == null){
timer = new Timer() {
@Override
public void run() {
uploadFileView.getBtnSubmit().fireEvent(Events.Select);
timer = null;
}
};
timer.schedule(100);
}
}
}
});
uploadFileView.addListener(Events.Show, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
presenter.getAppController().getFocusManager().setCurrentComponent(uploadFileView);
uploadFileView.getFileField().getFileInput().focus();
}
});
}
uploadFileView.show();
uploadFileView.getFileField().getFileInput().click();