当我第一次在数据库中上传文件时,如果用户上传相同的文件,我想向用户显示一个确认对话框,说“你要覆盖吗?是或否”。我该怎么做到这一点?
答案 0 :(得分:1)
尝试此操作,假设视图的代码如下:
<p:commandButton value="Upload" action="#{bean.save}" ajax="false" />
<p:confirmDialog widgetVar="confirmDlg" message="Do you want to override the file ?" >
<p:commandButton value="Yes" action="#{bean.overrideFile()} "type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
在托管bean中:
public void save(){
// condition about the file existence
// if true
RequestContext.getCurrentInstance().execute("PF('confirmDlg').show();");
}
...
public void overrideFile(){
// override the existent file here
}