【发布时间】:2016-12-02 09:05:49
【问题描述】:
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>
【问题讨论】:
-
尝试在你的 js 函数中使用
return false;。 -
还是不行,继续关闭。
-
我也认为你可能想要
actionListener而不是action,但我不是 100% 确定。 -
它有效。 :D 非常感谢@Apostolos。 :)
-
你能解释一下action和actionListener有什么不同吗?
标签: javascript jsf primefaces modal-dialog