title: play framework validation binding invalid input value with POJO
body: <p>I have a model TestModel.java which contains a field declared like below</p>
  
  <pre><code>@Required
  @IntegerAnnotation
  @Column (length = 4, nullable = false)
  public Integer sort;
  </code></pre>
  
  <p>For the default validation annotation of Play doesn't support Integer check, so I create an annotation validation for checking the input value is an Integer or not.</p>
  
  <p>The IntegerAnnotation.java :</p>
  
  <pre><code>@Retention(RetentionPolicy.RUNTIME)
  @Target({ElementType.FIELD, ElementType.PARAMETER})
  @Constraint(checkWith = IntegerCheck.class)
  public @interface IntegerAnnotation {
      String message() default IntegerCheck.message;}
  }
  </code></pre>
  
  <p>and this annotation refers to an implementations of IntegerCheck.java</p>
  
  <pre><code>public class IntegerCheck extends AbstractAnnotationCheck&lt;IntegerAnnotation&gt;{
  
  final static String message = "validation.integer";
  
  @Override
  public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) throws OValException {
      // TODO Auto-generated method stub
  
      if(value == null) return false;
      return isInteger(value.toString());
  }
  
  private static boolean isInteger(String s) {
      return isInteger(s,10);
  }
  
  private static boolean isInteger(String s, int radix) {
      if(s.isEmpty()) return false;
      for(int i = 0; i &lt; s.length(); i++) {
          if(i == 0 &amp;&amp; s.charAt(i) == '-') {
              if(s.length() == 1) return false;
              else continue;
          }
          if(Character.digit(s.charAt(i), radix) &lt; 0) return false;
      }
      return true;
  }
  }
  </code></pre>
  
  <p>And there are two actions in the controller for create or update the TestModel, method create and method update.</p>
  
  <pre><code>public static void create(@Valid TestModel testModel){
      if(validation.hasErrors()) {
          params.flash();
          validation.keep();
          blank();
      }
  }
  
  public static void update(@Valid TestModel testModel) {
  
      if(validation.hasErrors()) {
          params.flash();
          validation.keep();
      }
      else{
          testModel.save();
          show(sys5000.id);
      }
  }
  </code></pre>
  
  <p>I found when the field sort is not entered with integer value, the value will be null in the create method, that's why I put a if null condition in the IntegerCheck.class.</p>
  
  <p>Thus, if the value of filed sort is wrong typed, it detects null and return false.
  Though it's not what I expect it will use the wrong typed value to verify, it worked...sort of.</p>
  
  <p>The problem is in the update method.
  For when updating an instance of TestModel, it won't show the wrong typed value, but the original retrieved value from database instead.
  It's really a problem, for it will always return true if the retrieved data from database is already an integer. Then the validation won't do the work.</p>
  
  <p>And the questions are:</p>
  
  <ol>
  <li><p>Any advice for this validation strategy? I think maybe I'm apart from the right way to verify the Integer value validation.</p></li>
  <li><p>How can I retrieve the wrong typed value from the action, or it's just not possible, for it's already not a valid data type of that field.</p></li>
  </ol>