I have this class, where the field "nome" can't be empty
public class Utente {
......
@NotEmpty
@Size(min=2, max=30)
private String nome;
.......
}
After the user fills and sends the form I call this method
@RequestMapping("/formSent")
public String formSentMethod(Model model, @Valid Utente utente, BindingResult result){
.....
}
I print the error in the Eclipse's console with this plain code, put inside the formSentMethod method.
@RequestMapping("/formSent")
public String formSentMethod(Model model, @Valid Utente utente, BindingResult result){
.....
for(ObjectError errore : result.getAllErrors()){
System.out.println(errore.getDefaultMessage());
}
.....
}
So far, I get the default error message "may not be empty", when the user doesn't fill the field "nome".
I tried to customize that message by using a properties file called messages.properties, that I put under WEB-INF/classes, as you can see in this pic
Inside messages.properties I wrote
NotEmpty.utente.nome = Il nome è obbligatorio
In my XXX-servlet.xml I "call" the properties file this way
<bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource">
<property name="basename" value="messages" />
</bean>
<mvc:annotation-driven />
Since it didn't work I even tried editing the basename value this way
<property name="basename" value="WEB-INF/Classes/messages" />
but it didn't work as well.
I keep on getting the default error message and not my customized message "Il nome è obbligatorio". Probably what I wrote in my properties file is not correct. What am I doing wrong?