0 Replies Latest reply on Dec 22, 2009 3:40 AM by Markus Staab

    A4J validation in conjunction with JSF validation

    Markus Staab Newbie

      Hi everyone,


      I have the following non-Ajax4JSF code, where userBean is session scoped.

      The form has 2 input text boxes, one of which has a validator.  There is a simple commandButton to save it all.


      <h:inputText id="userLogin" value="#{userBean.selectedUser.login} validator="#{userBean.loginValidator}" />
      <h:message for="userLogin" />
      <h:inputText id="userFirstName" value="#{userBean.selectedUser.firstName}" />
      <h:commandLink value="save" action="#{userBean.saveUserAction}"/>


      This worked as expected -- if the user clicked "save" and the login name failed validation, the submitted values for both text fields were re-displayed, along with an error message next to the login field.


      So I wanted to add AJAX support for validation when the user blurred focus on the field.


      <h:inputText id="userLogin" value="#{userBean.selectedUser.login} validator="#{userBean.loginValidator}" >
        <a4j:support event="onblur" ajaxSingle="true" reRender="myMessages" />
      <rich:messages id="myMessages" />
      <h:inputText id="userFirstName" value="#{userBean.selectedUser.firstName}" />
      <h:commandLink value="save" action="#{userBean.saveUserAction}"/>


      When the user blurs focus on the text field, the validator is called and  the appropriate message is generated and displayed.

      However, if the user  clicks "save" anyway, I would expect the "Apply Request Values" phase to fail validation and re-display the submitted values.  This isn't what happens, and instead the submitted values are blank/null again ... and so all the changes made by the user are lost.

      If I remove the a4j:support tag, it immediately goes back to working as expected with the submitted values re-displayed upon validation error.

      Any help / tips / input would be appreciated.


      Thank you.