我有jQuery UI确认对话框:
I have jQuery UI confirm dialog:
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调用:
Called by JSF2 html:
<a4j:commandButton action="#{userBean.makeSomething()}" type="button" onclick="if (fnValidateUsersList()) {return fnComfirm('Delete User', 'Bla bla')}" />但是我无法从该函数获得true/false值.我在此站点上看到了许多有关此问题的信息,并尝试了所有问题,但仍然没有成功.
But I can't get true/false value from this function. I saw many questions here on this site about it, tried all of them, but still get no success.
更新: <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">推荐答案
这是我使用的一种方法(您可以将示例的总体思路作为参考)
Here an approach that I use (You can take the general idea for your example)
您需要两个按钮
第一个将被隐藏,并通过在确认对话框中单击Yes进行调用,该隐藏按钮将成为将调用服务器端方法并执行以下操作的按钮render使用f:ajax
First one will be hidden and will be called as a result of clicking Yes in the confirm dialog, this hidden button will be the one that will call the server side method and will do the render using the f:ajax
<h:commandButton id="myHiddenButtonID" value="DeleteHiddenButton" action="#{userBean.makeSomething()}" style="display:none"> <f:ajax render="@form" ></f:ajax> </h:commandButton>第二按钮将打开对话框,此按钮还将使用execute="@form"将表单提交到服务器(如果您在表中有选择列(选择表中的几列,然后单击按钮以显示).删除),例如您要在服务器Bean中更新的内容)
Second button will open the dialog, this button will also submit the form to the server with execute="@form" (in case you have selection column in table (select several columns in table and click button to delete) that you want to to update in the server bean for example)
<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();,否则将不会发生任何事情……
Notice that only upon clicking the OK dialog button there will be an execution of your hidden button $("#myHiddenButtonID").click(); otherwise nothing will happen...
从我过去回答过的类似问题中得到了答案如何使用JSF实现JQuery确认对话框
took this from similar question that I have answered in the past How to implement JQuery confirm dialog with JSF
更多推荐
jQuery UI确认对话框不返回true/false
发布评论