Witam,
Mam problem, ponieważ nie działa walidacja. W modelu na polu mam adnotację NotNull, nie uzupełniam tego pola, więc powinno zwrócić z powrotem stronę z formularze, a tymczasem przechodzi do success. Mam jeszcze dodany spring-security, czy potrzebuje dodać jakiś filter jeszcze w web.xml dla walidatora? Całą konfigurację mam w plikach xml.
@RequestMapping(method = POST)
public ModelAndView create(@Valid @ModelAttribute("newFoo") Foo
newFoo) {
if (binder.hasErrors()) {
// return to the form
...
}
...//success
}
@InitBinder("newFoo")
public void initialiseBinder(WebDataBinder binder) {
binder.setDisallowedFields("id" /*"status",*/ );
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
//Register it as custom editor for the Date type
binder.registerCustomEditor(Date.class, editor);
}
<mvc:annotation-driven enable-matrix-variables="true" validator="validator"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<!--<property name="validationMessageSource" ref="messageSource" />-->
</bean>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator-version}</version>
</dependency>
Wersja hibernate-validator: 5.2.2.Final
Wersja springa: 4.1.1.RELEASE