4 Replies Latest reply on Nov 15, 2007 4:43 PM by pmuir

    Custom validator disables hibernate default validator

    dapeng

      Hi,

      on one column (property) of my entity, a unique constraint needs to be defined. To avoiding a duplication of this property, I implemented a custom validator method to check the uniqueness. So far it works fine. But I found out, that the default hibernate validator doesn't work anymore (have got a @Length (max=11) annotation on the same property), as soon as the validator binding is added to the component, though the text field is put inside a validateAll tag.

      <h:inputText id="vinPrefix" value="#{entity.vinPrefix}" required="true" label="#{masterDataMsgs['vingroup.edit.label.name']}" styleClass="text" rendered="#{entity.transient}" validator="#{vinGroupEditAction.checkVinPrefix}">
      <a4j:support event="onblur" reRender="vinPrefixDecorate" />
      </h:inputText>
      


      After checking the source code, I found the following line in the method addValidators of ValidateAllRendererBase.java.

      if ( evh.getValidators().length==0 && evh.getValidators().length == 0 )
       {
       evh.addValidator( new ModelValidator() );
       }


      First of all, I don't understand, why you check the same condition twice. Second, I have no clue, why you only add the ModelValidator, if here is no other validator. I would exactly like to combine the hibernate validator with my custom one.

      Any explanation is appreciated