4 Replies Latest reply on Feb 11, 2011 8:12 AM by Mikael Brodd

    Custom validators vs Hibernate validators

    Mikael Brodd Newbie

      Hi,


      I am trying to understand the possible combinations of different validators (to be run simoultaneously).


      Adding a custom validator to my xhtml seems to make the Hibernate validator to not be run. Is that so?


      Here is an example of my custom validator in xhtml:



      <s:decorate id="vpnIdField" template="/view/c_edit.xhtml">
           <ui:define name="label">VPN Id</ui:define>
           <h:inputText id="vpnIdInputText"
                     value="#{vpnHome.instance.vpnCounter}" 
                     required="true"
                     validator="vpnUniqueIdValidator"
                     disabled="#{vpnAction.guiDisabled}">
                 <a4j:support event="onblur"
                        action="#{vpnAction.generateTechId()}"
                        reRender="vpnIdField, vpnTechIdField" 
                        ajaxSingle="true"/>
           </h:inputText>
      </s:decorate>
      



      Now I have enabled Hibernate validation on an entity that is affected by the input field and custom validator




          @Column(name="VPN_COUNTER", nullable=true, precision=3, scale=0)
          @Range(min=1, max=99, message="VPN Id must be between 1 and 99")
          public Long getVpnCounter() {
              return this.vpnCounter;
          }
      



      If I run this code and enter a VPN Id of 101 in the vpnIdInputText, no validation occurs. But if I remove the custom validator from the xhtml, the hibernate validator works. Is it supposed to be that way? Or have I done something wrong in order to make both validators take effect?


      regards - Mikael