title: Form validations (Server Side) examples in ZK MVVM
body: <p>Can you please explain how to do form validations on the server side using the MVVM approach. I tried it but could not do it effectively. I have done small validations on the client side using intbox etc. 
  But I want to do validations like:</p>
  
  <blockquote>
    <ol>
    <li>The value of an attribute should not exceed say 100.</li>
    <li>If value of attribute A is filled by the user then attribute B becomes mandatory and like that.</li>
    <li>If value of attribute A is 100 and B is 50 then value of attribute C becomes mandatory and cannot exceed 150</li>
    </ol>
  </blockquote>
  
  <p>I am not able to figure out a way of doing it in MVVM. I am using ZK CE 6.0.0 version.</p>
  
  <p>I tried the code mentioned below: </p>
  
  <p>Validation.zul</p>
  
  <pre><code>&lt;zk&gt;
      &lt;window title="Validation" border="normal"
          apply="org.zkoss.bind.BindComposer" id="validtionWin"
          viewModel="@id('vm') @init('com.nagarro.validator.CustomValidator')"&gt;
          &lt;intbox
              value="@save(vm.quantity) @validator(vm.rangeValidator)" /&gt;
  
          &lt;button label="Submit"&gt;&lt;/button&gt;
      &lt;/window&gt;
  &lt;/zk&gt;
  </code></pre>
  
  <p>ViewModel
  CustomValidator.java</p>
  
  <pre><code>import org.zkoss.bind.ValidationContext;
  import org.zkoss.bind.Validator;
  import org.zkoss.bind.validator.AbstractValidator;
  
  
  public class CustomValidator implements Validator{
  
      private Validator rangeValidator;
  
      private String quantity;
  
      /**
       * @return the quantity
       */
      public String getQuantity() {
          return quantity;
      }
  
      /**
       * @param quantity
       *            the quantity to set
       */
      public void setQuantity(String quantity) {
          this.quantity = quantity;
      }
      @Override
      public void validate(ValidationContext ctx) {
  
  
      }
  
      /**
       * @return the rangeValidator
       */
      public Validator getRangeValidator() {
          return new AbstractValidator() {
              public void validate(ValidationContext ctx) {
                  Integer val = (Integer)ctx.getProperty().getValue();
                  if(val&lt;10 || val&gt;100){
                      addInvalidMessage(ctx, "value must not &lt; 10 or &gt; 100, but is "+val);
                  }
              }
          };
      }
  
      /**
       * @param rangeValidator the rangeValidator to set
       */
      public void setRangeValidator(Validator rangeValidator) {
          this.rangeValidator = rangeValidator;
      }
  
  }
  </code></pre>
  
  <p>Please figure out the mistake in the above code. :)</p>
  
  <p>I get the following WARNING when I run the above code.</p>
  
  <pre><code>Jan 16, 2013 4:58:07 PM org.zkoss.bind.validator.AbstractValidator
  addInvalidMessages:84 WARNING: ValidationMessages not found on binder
  org.zkoss.bind.AnnotateBinder@cf7fda, please init it
  </code></pre>
  
  <p>How should I set the validation Message Please Help. :)</p>