简体   繁体   中英

JSF Validation error is not displaying before close Jquery dialog

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM