问题
I have a Jquery dialog to get user input.
<div id="icPopup">
<td>
<h:selectOneMenu id="selectICType" value="#{sessionBean.icStartLetter}" required="true" requiredMessage="Select IC type" style="width:100px;">
<f:selectItem itemValue="" itemLabel="- Select -"/>
<f:selectItems value="#{sessionBean.icStartLetterTypes}"/>
</h:selectOneMenu>
</td>
<td align="center">
<h:inputText id="icNumber" value="#{sessionBean.icNumber}"></h:inputText>
</td>
<td>
<div id="mainBtnGrey" class="mainBtnLeftAlign">
<h:commandLink action="#{home.checkICForError}" value="Confirm"/>
</div>
</td>
</div>
And my script code is
$('#mainBtnGrey').click(function (e) {
e.preventDefault();
$('#icPopup').dialog('close');
});
The issue here is, before display the validation errors the dialog is closed. How to keep open the dialog if the bean return the validation errors?
回答1:
If your script code is present on the XHTML page within <script/>
, you could just check the validation status of the EL using:
$('#mainBtnGrey').click(function (e) {
e.preventDefault();
if(!#{facesContext.validationFailed})
$('#icPopup').dialog('close');
});
facesContext.validationFailed
will check the validation status of the entire JSF request for failure.
来源:https://stackoverflow.com/questions/27224338/jsf-validation-error-is-not-displaying-before-close-jquery-dialog