我正在使用 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();