3 Replies Latest reply on Mar 19, 2009 6:53 PM by Nick Belaevski

    How to use Hibernate AssetTrue with beanValidator?

    Ivo Jánský Newbie

      Hey,

      does anyone know how to use Hibernate's validator AssertTrue with beanValidator tag? What I need is to check whether email address is unique, but the corresponding method in the backing bean is not called. (Actually I have no idea how to call it.). Validation on the getMailboxAddress function works just fine.

      Here is the code of the backing bean

      
       @Pattern(regex = "^[a-zA-Z0-9._%+-]+$")
       public String getMailboxAddress() {
       if (mailbox == null) {
       return null;
       }
      
       if (mailbox.getAddress() != null) {
       int indexOfDomain = mailbox.getAddress().indexOf(mailbox.getMailDomain().getDescription()) - 1;
       return mailbox.getAddress().substring(0, indexOfDomain);
       }
      
       return null;
       }
      
       @AssertTrue(message = "{addressIsNotUnique}")
       public boolean isAddressUnique() {
       if (mailbox == null) {
       return false;
       }
      
       EmailService emailService = new EmailService();
       if (emailService.findMailboxByAddress(mailbox.getAddress()) == null) {
       return true;
       }
      
       return false;
       }
      


      Here is the xhtml page

      <h:inputText id="username" label="#{emailBundle.mailboxAddress}" required="true" value="#{modules$email$MailboxEditBean.model.mailboxAddress}">
       <rich:beanValidator/>
      </h:inputText>
      


      Thanks for any help!