views:

434

answers:

2

Hello, i am working on a JSF Projekt with Glassfish. My validation works well but i dont become a custom error message.

//Class = User, package = devteam
@NotEmpty @Pattern(".+@.+\\.[a-z]+")
private String emailAddress;

My ValidationMessages.properties is in the WEB-INF folder with this content:

devteam.User.emailAddress=Invalid e-mail address

Thank you.

+1  A: 

You are having two problems here. First, the location of the ValidationMessages.properties file. It has to be in the root of the classpath, so move it into WEB-INF/classes Your second problems are the message keys. The default message key for the Pattern constraint for example is {javax.validation.constraints.Pattern.message}. In your case you want to specify the message parameter in the @Pattern annotation:

@Pattern(pattern=".+@.+\\.[a-z]+", message="{devteam.User.emailAddress}")
Hardy
Thank you. This works greate
ThreeFingerMark
A: 

You should put the file in the root, then devteam.User.emailAddress[Pattern] = "Your message here"

notice [Pattern] to specify the message to output when the Pattern has a constraint violation. this makes it easier to maintain in my opinion vs having the messages like @Patterh(regexp ="xx", message = "your message here") for every setter

Dick Solomon