title: Validating a group of fields in grails domain object
body: <p>I have a command object that captures a feedback form with 3 textareas. </p>
  
  <pre><code>class FeedbackCommand {
      String textarea1
      String textarea2
      String textarea3
      String username 
  
      static constraints = {
          textarea1(nullable:true, blank:true)            
          textarea2(nullable:true, blank:true)            
          textarea3(nullable:true, blank:true)            
          username(nullable:false, blank:false)
      }
  }    
  </code></pre>
  
  <p>I'd like to ensure that at least ONE of the textareas is filled out.  </p>
  
  <p>I came up with adding a fake flag field as a 'constraint' field, and then doing a bunch of object checks in the custom validator for that field.  If after looking around in myself and i dont find what I want, I throw an error. </p>
  
  <p>Right now, I'm doing this:</p>
  
  <pre><code>class FeedbackCommand {
      String textarea1
      String textarea2
      String textarea3
      boolean atLeastOne = true
      String username 
  
      static constraints = {
          textarea1(nullable:true, blank:true)            
          textarea2(nullable:true, blank:true)            
          textarea3(nullable:true, blank:true) 
          atLeastOne(validator: { boolean b, FeedbackCommand form, Errors err -&gt;
            if (b) {
              if ( (form.textarea1==null || form.textarea1?.isAllWhitespace()) &amp;&amp;
                   (form.textarea2==null || form.textarea2?.isAllWhitespace()) &amp;&amp;
                   (form.textarea3==null || form.textarea3?.isAllWhitespace()))
              {
                  // They havent provided ANY feedback. Throw an error
                  err.rejectValue("atLeastOne", "no.feedback")
                  return false
              }
            }
            return true             
          })           
          username(nullable:false, blank:false)
      }
  }
  </code></pre>
  
  <p>Is there a better way to </p>
  
  <ul>
  <li>validate a related/group of fields  (at least one can't be blank, 2 should have values, etc)?</li>
  <li>a groovier way to express "at least one shouldnt be null/blank" rather than my gross if-statement block?</li>
  </ul>
  
  <p>Thanks</p>