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

    Some advice for trapping unique validation

    Franco Fernandes Novice

      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" 
                          <f:validator validatorId="uniqueTaxValidator"  />       
                          <a4j:support event="onblur" reRender="taxCodeDecoration" bypassUpdates="true" ajaxSingle="true"/>

      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")
           @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