I have a situation similar to the followa:
public class Shop {
@NotNull
String name;
@NotNull
String desc;
}
a button to show a form where I have to insert my user:
<form:form method="post" action="saveShop.html" modelAttribute="Shop">
<form:label path="name">Name:</form:label>
<form:input path="name" value="${shop.name}" />
<form:label path="desc">desc:</form:label>
<form:input path="desc" value="${shop.desc}" />
<input type="submit" value="Submit"/>
</form:form>
Controller:
@RequestMapping("/addShop")
public ModelAndView LoadFormPage(@ModelAttribute("Shop")Shop shop) {
ModelAndView model = new ModelAndView();
model.setViewName("/shop/addShop");
return model;
}
@RequestMapping(value = "/saveShop", method = RequestMethod.POST)
public ModelAndView saveShop(@Valid @ModelAttribute("Shop") Shop shop, BindingResult result) {
if (result.hasErrors()) { *do some*
} else { *do someelse* }
}
Even if I leave all fields blank (I have tried even with different data type) and submit the form the controller never recognize errors.
Can you help me?