1
我對primefaces
對話框有問題。我有自定義驗證。 我創建了javascript方法來保持自定義驗證失敗時打開的對話框。 雖然驗證失敗,但它仍然關閉。如何使用javascript保持primefaces對話框打開
這裏是我的代碼:
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>
詳細解釋請嘗試使用'返回false;'你的js函數。 – Apostolos
仍然無法工作,請繼續關閉。 – Alice
我也認爲你可能需要'actionListener'而不是'action',但我不是100%肯定的。 – Apostolos