如何使用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的区别吗。