【问题标题】:Primefaces call ConfirmDialog from BackingPrimefaces 从 Backing 调用 ConfirmDialog
【发布时间】:2014-03-16 10:34:49
【问题描述】:

我想通过支持致电confirmDialog。此代码完美运行,但我如何设置消息并通过支持设置confirmDialog 的actionlistener?有两个条件,while:

  • 用户勾选复选框上的选项A(我省略了代码),那么它应该直接打印一个文本到控制台。 --> 这是由下面的代码完成的
  • 用户选中复选框上的选项 B,然后它应该显示确认对话框,当用户按下 YES 按钮时,它应该在后台调用另一个函数。

如何做到这一点?谢谢。

<p:commandButton value="Execute" icon="ui-icon-circle-check"  update="frmContent" actionListener="#{backing.validate}" />

<p:confirmDialog id="cfmDlg" widgetVar="wvCfmDlg" global="true" >
    <p:commandButton value="Yes" 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>

在后台:

public void validate() {
    if(mode.equals("1")) {
        System.out.println("OK");
    } else {
        //call confirmDialog and set message + action listener
        RequestContext context = RequestContext.getCurrentInstance();
        context.execute("wvCfmDlg.show();");
    }
}

【问题讨论】:

  • 你是什么意思“ConfirmDialog的动作监听器通过backing bean????
  • @Makky:我的意思是,我怎样才能通过 backing bean 设置 confirmDialog 的 actionlistener + message(在 xhtml 中,你应该这样做:actionListener=""message="")只是比如primefaces.org/showcase/ui/confirmDialog.jsf

标签: java primefaces


【解决方案1】:

如果我正确理解你的问题..我会这样做。

xhtml

<p:commandButton style="display: none" 
                 widgetVar="confirmButton"  
                 actionListener="#{backing.yesFunction}" >
   <p:confirm header="Confirmation" message="Are you sure?" /> 
</p:commandButton>

<p:commandButton value="Execute"
                 actionListener="#{backing.validate}" /> 

<p:confirmDialog id="cfmDlg" global="true" >
      <p:commandButton value="Yes" />
      <p:commandButton value="No" />
</p:confirmDialog>

public void validate() {
   if(mode.equals("1")) {
       System.out.println("OK");
   } else {
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('confirmButton').jq.click();");
   }
}

基本上,您以通常的方式添加一个隐藏按钮(带有 p:confirm),然后通过 jQuery 单击它。

【讨论】:

  • 这正是我想要的。非常感谢,你真的节省了我的时间:)
  • 感谢@HatemAlimam 对 PrimeFaces 5.0 以上版本的小信息,您应该使用 context.execute("PF('confirmButton').jq.click();");
  • @ÖmerFarukKurt 你是对的,因为这是一个有点旧的帖子我没有更新它,现在它已经更正了:)
猜你喜欢
  • 2014-08-10
  • 2015-12-10
  • 1970-01-01
  • 2012-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-05
相关资源
最近更新 更多