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.requiredvalidation, ensures value not null.@formats.nonemptyformatter, 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
Post a Comment