hardy.ferentschik wrote:
Looking at the stack trace Validator does not even seem to be called yet. Not sure what's going on there. Can you describe more your framework stack? Which value do you try to validate? How do you enable Validator, etc
--Hardy
Hi Hardy,
Thanks very much your quick rely.
The stack trace is copied from the top of exception trace. You are right. I am fully aware that the Hibernate Validator was not even called yet. When I leave the field blank, I get "may not be empty" (twice). I guess the message is a native validator message. I don't know why it shows up twice, however.
We use the Spring MVC framework 3.0. It enables the Validator with an annotation @Valid. In this case,
Code:
public String submit(
@Valid @ModelAttribute("usernameRetrieval") UsernameRetrievalForm usernameRetrieval,
BindingResult result, SessionStatus status, Model m) {
if (result.hasErrors()) {
logger.debug("validation error");
result.rejectValue("email", "INVALID_EMAIL", result.getFieldErrors(
"email").get(0).getDefaultMessage());
return "profile.usernameRetrievalForm";
}
...
}
That is how Spring MVC handles validation with the Hibernate Validator. If I have a whitespace or a random string such as "svbe", I will get the exception.
Can I ask you a related question? Messages from Hibernate Validator can be quite verbose. That is good for providing an insightful information. That is not too good for UI though, too much text beside a UI component. Is a way to customize a validator error message in an i18n environment (that is a text on Java code is a message key in a message file)?
________________________________________________________________________
Having your web bookmarks anywhere you go -
http://homepage.kgbinternet.com