Validation
We wouldn't want our user to enter invalid or empty information and that's why we will need to add some validation logic to our ProfileForm
.
package masterspringmvc4.profile; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Past; import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.Date; import java.util.List; public class ProfileForm { @Size(min = 2) private String twitterHandle; @Email @NotEmpty private String email; @NotNull private Date birthDate; @NotEmpty private List<String> tastes = new ArrayList<>(); }
As you can see, we added a few validation constraints. These ...
Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.