我有 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,"if (fnValidateUsersList()) {return fnComfirm('Delete User', 'Bla bla')}","RichFaces.ajax(\"frm:j_idt25\",event,{\"incId\":\"1\"} )");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/