【问题标题】:How to display a confirm dialog in JSF?如何在 JSF 中显示确认对话框?
【发布时间】:2015-12-20 07:04:13
【问题描述】:

当我第一次在数据库中上传文件时,然后如果用户上传相同的文件,我想向用户显示一个确认对话框,上面写着“你要覆盖吗?是或否”。我应该如何做到这一点?

【问题讨论】:

  • 您应该首先实现一种方法来检查相关文件的可用性。然后看这里:Primefaces confirm dialog + How to use PrimeFaces p:fileUpload? Listener method is never invoked.
  • 我已经在我的后台 bean 中实现了检查文件是否存在的方法。我说得对,但问题是如何显示“文件已存在”的对话框或消息?
  • 您在使用 Primefaces 吗?如果是,是哪个版本?
  • 答案取决于您使用的 UI 组件库(或者如果您只是使用“plain vanilla”JSF)
  • Balus C- UI 组件库?意味着

标签: jsf confirm-dialog


【解决方案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
}

【讨论】:

    猜你喜欢
    • 2016-10-08
    • 2014-04-08
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多