So I just set up hibernate validation using annotation.
Basically something like this
@NotNull(message="please enter your first name")
@Size(min=5, max=25, message = "your name is under or over the allotted size)
String lastName
The validation itself works fine for the most part. The size component will trigger on submit. However, if I load the page it's validating the NotNull validation will trigger the moment it loads reminding the user to fill in the blank input. Since this is triggered in the bean, and I'm still rather new to Spring MVC I was wondering if there was anything I could do to have it trigger on submit instead of load.
Controller code...
@RequestMapping(value = "/App")
public ModelAndView loadAppPage(@RequestParam(value = "Sal", required = false) String Sal,
@RequestParam(value = "name1", required = false) String name1,
@RequestParam(value = "name2", required = false) String name2,
@ModelAttribute("newApp")@Valid App newApp, BindingResult result){
ModelAndView mav = new ModelAndView();
String timestamp = new java.text.SimpleDateFormat("MM/dd/yyyy h:mm:ss a").format(new Date());
if(sal != null || name1 != null || name2 != null |){
newContact.setSal(Sal);
newContact.setname1(name1);
newContact.setname2(name2);
new AppValidator().validate(newApp, result);
if(result.hasErrors()){
return new ModelAndView("App", "newApp", newApp);
}else{
appService.addApp(newApp);
/* mav.addObject("newApp", new App());*/
mav.setViewName("redirect:App.html");
return mav;
}
}
mav.addObject("newApp", newApp);
mav.setViewName("App");
return mav;
}