playframework - What's the difference between @Constraints.Required and @Formats.NonEmpty? -


when creating model in play! 2.x, can use @constraints.required , @formats.nonempty. understand them, same, zentasks sample uses them both in same field, i'm wrong. why?

public class user extends model {      @id     @constraints.required     @formats.nonempty     public string email;      ... } 

constraints , formats have complete different targets. once formatting , other vaildation, so

  • @constraints.required validation, ensures value not null.
  • @formats.nonempty formatter, trims input , if string has length of 0 (text.trim().isempty()) returns null. value set null. after required-annotation can job.

so it's useful use both, not in every situation.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -