0 Replies Latest reply on Oct 14, 2008 4:53 PM by francof

    Some advice for trapping unique validation

      I am not sure I understand the sequence of validations.


      I have this field


                 <s:decorate id="taxCodeDecoration" template="layout/edit.xhtml">
                      <ui:define name="label">#{messages.tax_taxCode}</ui:define>
                      <h:inputText id="taxCode" 
                             required="true"
                     requiredMessage="#{messages.reqd_taxCode}"                       
                                 size="10"
                             disabled="#{taxHome.managed}"
                            maxlength="10"
                                value="#{taxHome.instance.taxCode}">
                          <f:validator validatorId="uniqueTaxValidator"  />       
                          <a4j:support event="onblur" reRender="taxCodeDecoration" bypassUpdates="true" ajaxSingle="true"/>
                      </h:inputText>
                  </s:decorate>
      



      In the above code, I call a custom validator to checks for unique code.


      and my entity Tax has these validations set on field taxCode


           @Column(name = "TAX_CODE")
           @NotNull
           @Length(max = 10)
           @Pattern(regex="^\\d*$", message="You can enter only numbers into this field")
           public String getTaxCode() {
                return this.taxCode;
           }
      



      When happens here is that my @Pattern validation never gets fired. If I enter a duplicate value, my custom validator is called correctly, but then I can enter a alphanumeric value thus ignoring my @Pattern rule.


      If I remove the custom validator, @Pattern works fine.


      Ideally, I would like to trap the unique validation on @PrePersist, but that would also mean that this will happen only after the user has entered all fields on the forms and hit the Save button.


      How do you experienced Seam guys handle this ?


      Thanks in advance