jquery-ui - jQuery UI 确认对话框不返回 true/false

标签 jquery-ui jsf-2 jquery-ui-dialog

我有 jQuery UI 确认对话框:

function fnComfirm(title, content) {
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-confirm p").html(content);
    $("#dialog-confirm").dialog({
        title: title,
        resizable: false,
        height: 200,
        width: 486,
        modal: true,
        buttons: {
            "OK": function() {
                $( this ).dialog("close");
                return true;
            },
            Cancel: function() {
                $( this ).dialog("close");
                return false;
            }
        }
    });
}

由 JSF2 html 调用:

<a4j:commandButton action="#{userBean.makeSomething()}"  type="button" onclick="if (fnValidateUsersList()) {return fnComfirm('Delete User', 'Bla bla')}" />

但是我无法从此函数中获取真/假值。我在这个网站上看到了很多关于它的问题,尝试了所有这些,但仍然没有成功。

更新: <a4j:commandButton>的输出:

<input type="button" value="Make Something" onclick="jsf.util.chain(this,event,&quot;if (fnValidateUsersList()) {return fnComfirm('Delete User', 'Bla bla')}&quot;,&quot;RichFaces.ajax(\&quot;frm:j_idt25\&quot;,event,{\&quot;incId\&quot;:\&quot;1\&quot;} )&quot;);return false;" name="frm:j_idt25" id="frm:j_idt25">

最佳答案

这是我使用的一种方法(您可以将总体思路用于您的示例)

您需要两个按钮

第一个按钮将被隐藏,并在确认对话框中单击后被调用,该隐藏按钮将是调用服务器端的按钮方法,并将使用 f:ajax

进行render
<h:commandButton id="myHiddenButtonID" value="DeleteHiddenButton" action="#{userBean.makeSomething()}" style="display:none">
    <f:ajax render="@form" ></f:ajax>
</h:commandButton>

第二个按钮将打开对话框,此按钮还将使用 execute="@form" 将表单提交到服务器(如果表中有选择列) (例如,选择表中的几列,然后单击按钮删除)您想要在服务器 bean 中更新)

<h:commandButton value="Delete">
    <f:ajax execute="@form" onevent="openDialogFunc()"></f:ajax>
</h:commandButton>

现在开始js函数的实现

function openDialogFunc(data){
    if (data.status === 'success') {
        $('#dialog').dialog({
                    title: title,
                    resizable: false,
                    height: 200,
                     width: 486,
                     modal: true,
         buttons: {
                 "Ok": function() { 
                     $("#myHiddenButtonID").click();
                     $(this).dialog("close"); 
                 }, 
                 "Cancel": function() { 
                     $(this).dialog("close"); 
                 } 
             }
         });
    }
}

请注意,只有单击“确定”对话框按钮后,才会执行隐藏按钮 $("#myHiddenButtonID").click(); 否则什么也不会发生...

取 self 过去回答过的类似问题How to implement JQuery confirm dialog with JSF

关于jquery-ui - jQuery UI 确认对话框不返回 true/false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11416553/

相关文章:

jQuery animate() 和appendTo() 问题

javascript - jQuery UI "Loading..."错误处理

ajax - 如何通过 f :ajax when losing focus of second field? 验证两个密码字段

jquery - 在 jQuery UI 对话框中显示复选框并提供取消按钮

jQuery UI 对话框叠加 - 如何为不同的对话框设置不同的背景颜色

html - 一键实现多个jquery-ui对话框

jQuery 移动 slider 禁用但不灰显

javascript - jQuery 对话框中的 jQuery 元素在 ajax 调用后停止工作

jsf-2 - 将参数从 Action 方法传递到下一个 View

jsf-2 - 用于货币输入的 Primefaces 输入(浮点后正好 2 位数字)