title: How to use custom validator in Grails
body: <p>I'm new in Grails. I would like to use custom validator for matching two passwords during registration in my application. Unfortunetly doesn't work it.</p>
  
  <p><strong>Account.groovy</strong></p>
  
  <pre><code>@Validateable
  class Account {
  
      String login
      String password
      String confirm
      String passwordHashed
      char active
      static transients = ['password', 'confirm']     
      static belongsTo = Employee
      static hasMany = [role:Role]
  
      static constraints = {
          login unique:true, blank: false
          active nullable: true
          password blank: false, size: 5..15, validator:{ val, obj -&gt;
              if(obj.password != obj.confirm ){
                  return ['dontmatch']
              }
          }       
      }
  
      static mapping = {
          id generator: 'increment'
      }
  }
  </code></pre>
  
  <p><strong>AuthenticationController.groovy</strong></p>
  
  <pre><code>class AuthenticationController {
  
      def signUp(Account accountInstance){
  
          if(accountInstance!= null){
              if (accountInstance.hasErrors()) {
                  respond accountInstance.errors, view:'signUp'
                  return
              }
              else{
                  accountInstance.save(flush: true)
              }
          }
      }
  
  }
  </code></pre>
  
  <p><strong>signUp.gsp</strong></p>
  
  <pre><code>&lt;%@ page import="com.sarna.entity.Account"%&gt;
  &lt;%@ page import="com.sarna.entity.Employee"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta name="layout" content="bootstrap-main" /&gt;
  &lt;title&gt;SARNA&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;br /&gt;
      &lt;div class="container"&gt;
          &lt;div style="margin-top: 50px"
              class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2"&gt;
              &lt;div class="panel panel-info"&gt;
                  &lt;div class="panel-heading"&gt;
                      &lt;div class="panel-title"&gt;Sign Up&lt;/div&gt;
                      &lt;div
                          style="float: right; font-size: 85%; position: relative; top: -10px"&gt;
                          &lt;a id="signinlink"
                              href="${createLink(uri: '/authentication/signIn') }"&gt;Sign In&lt;/a&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="panel-body"&gt;
                      &lt;g:form class="form-horizontal" role="form"
                          url="[resource: accountInstance]"
                          method="POST" controller="Authentication"&gt;
  
  
                          &lt;g:hasErrors bean="${accountInstance}"&gt;
                              &lt;div class="alert alert-danger"&gt;
                                  &lt;g:renderErrors bean="${accountInstance}" /&gt;
                              &lt;/div&gt;
                          &lt;/g:hasErrors&gt;
                          &lt;div class="form-group"&gt;
                              &lt;label for="email" class="col-md-3 control-label"&gt;Email&lt;/label&gt;
                              &lt;div class="col-md-9"&gt;
                                  &lt;input type="text" class="form-control" name="email"
                                      placeholder="Email Address"&gt;
  
                              &lt;/div&gt;
                          &lt;/div&gt;
  
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="icode" class="col-md-3 control-label"&gt;Login&lt;/label&gt;
                              &lt;div class="col-md-9"&gt;
                                  &lt;g:textField type="text" class="form-control" name="login"
                                      required="" value="${accountInstance?.login }"
                                      placeholder="Login" /&gt;
  
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="password" class="col-md-3 control-label"&gt;Password&lt;/label&gt;
                              &lt;div class="col-md-9"&gt;
  
                                  &lt;g:passwordField name="password"
                                      class="form-control ${hasErrors(bean:accountInstance,field:'password','errors')}"
                                      placeholder="Password" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;label for="icode" class="col-md-3 control-label"&gt;Confirm&lt;/label&gt;
                              &lt;div class="col-md-9"&gt;
                                  &lt;g:passwordField
                                      class="form-control ${hasErrors(bean:accountInstance,field:'password','errors')}"
                                      name="confirm" placeholder="Confirm Password" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;!-- Button --&gt;
                              &lt;div class="col-md-offset-3 col-md-9"&gt;
  
                                  &lt;g:actionSubmit action="signUp"
                                      class="btn btn-lg btn-success btn-block" value="Sign Up" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/g:form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>messages.properties</strong></p>
  
  <pre><code>account.password.dontmatch=Podane hasła muszą się zgadzać
  </code></pre>
  
  <p>I don't understand it. I enter two different passwords and I click signUp button, I don't see errors messages which should be display when validation failed. Could you help me?</p>