2 Replies Latest reply on Jul 23, 2009 5:55 PM by Vitor Souza

    Seam + a4j:support re-rendering + Hibernate Validator @Pattern

    Vitor Souza Newbie

      Hello,


      Maybe this should be sent in Hibernate's forum or in Ajax4J's forum, but since Seam is the one that puts everything together and I got the idea of using a4j:support for AJAX validation in the Reference guide for Seam, I'm posting here. Sorry if misplaced.


      I have a form with AJAX Validation like this:


      <s:decorate id="zipCodeDecoration" template="/resources/templates/#{applicationInformation.decorator}/formfield.xhtml">
           <ui:define name="label"><h:outputText value="#{messages['manageSpiritists.form.zipCode']}" /></ui:define>
           <h:inputText id="zipCode" value="#{selectedEntity.address.zipCode}" size="10" disabled="#{readOnly}">
                <a4j:support event="onblur" reRender="zipCodeDecoration" bypassUpdates="false" />
                <rich:jQuery selector="#zipCode" query="mask('99999-999')" timing="onload" />
           </h:inputText>
      </s:decorate>




      An on the zipCode property in the Address class, I had the Hibernate Validator annotation @Pattern(regex = "[0-9]{5}-[0-9]{3}"), representing the Brazilian ZIP code format: 99999-999.


      With this regular expression, the form does not accept null values. If I leave the field blank, it warns me when I leave the field (onblur) and it throws an exception if I try to submit the form.


      I tried changing the expression to () or ([0-9]{5}-[0-9]{3}) (the () in the beginning would accommodate for empty strings. This way it accepts sending the form without a value in the field (no exception thrown anymore), but it still warns me onblur.


      A note on Seam Text: in the new regular expression above, where there is or , there should be a pipe: |. I tried putting \| in the expression, but it kept giving me an error. In other words, Seam Text doesn't accept |\||. Close parenthesis...


      What's the right way to indicate that I want either a null/empty field, or a field with the specified pattern?


      Thanks,


      Vítor Souza