Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript保持primefaces对话框打开_Javascript_Jsf_Primefaces_Modal Dialog - Fatal编程技术网

如何使用javascript保持primefaces对话框打开

如何使用javascript保持primefaces对话框打开,javascript,jsf,primefaces,modal-dialog,Javascript,Jsf,Primefaces,Modal Dialog,我对primefaces对话框有问题。我有自定义验证。 我创建了javascript方法,以在自定义验证失败时保持对话框打开。 但是,尽管验证失败,它仍在继续关闭 这是我的密码: function alertMsg() { var str1 = document.getElementById("templateForm:resultMsg").textContent; var str2 = "Duplicate name."; if(str

我对
primefaces
对话框有问题。我有自定义验证。 我创建了javascript方法,以在自定义验证失败时保持对话框打开。 但是,尽管验证失败,它仍在继续关闭

这是我的密码:

function alertMsg()
    {
        var str1 = document.getElementById("templateForm:resultMsg").textContent;
        var str2 = "Duplicate name.";
        if(str1.localeCompare(str2) == 0)
        {
            alert("inside same!")
            PF(dlg).show(); //Although i try to keep open, this dialog always close.
        }
    }

 .....some code
<p:dialog header="Add" widgetVar="dlg" id="add" resizable="false" modal="true" closable="false" width="600px" >
<h:panelGrid columns="4" cellpadding="5" > 
    <p:outputLabel value="Name" style="width:130px;"/>
    <p:outputLabel  value=":" style="width:15px;"/>
    <h:inputText id="Name" value="#{Bean.Name}" styleClass="form-control"  style="width:300px;" required="true" requiredMessage="!" >
    </h:inputText>
    <h:outputText id="resultMsg1" value="Duplicate name." style="color:red; width:30px;"/>
</h:panelGrid>

<p:commandButton process="@parent" ajax="true" value="Save" onstart="alertMsg()"
                                    update= templateForm:resultMsg" action="#{Bean.save()}" styleClass="btn btn-danger">
                                    </p:commandButton>

</p:dialog>
函数alertMsg()
{
var str1=document.getElementById(“templateForm:resultMsg”).textContent;
var str2=“重复的名称。”;
if(str1.localeCompare(str2)==0)
{
警报(“内部相同!”)
PF(dlg).show();//虽然我试图保持打开状态,但此对话框始终关闭。
}
}
…一些代码

请使用
actionLinstener
而不是
action


您可以找到这两者的详细解释

尝试使用
返回false在你的js函数中。仍然无法工作,请继续关闭。我还认为你可能需要
actionListener
而不是
action
,但我不是100%确定。它可以工作:D非常感谢@Apostolos.)你能解释一下action和actionListener的区别吗。