Bean Validation and error messages at .properties file

后端 未结 2 1690
半阙折子戏
半阙折子戏 2020-12-09 23:28

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          


        
相关标签:
2条回答
  • 2020-12-10 00:16

    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(regexp=".+@.+\\.[a-z]+", message="{devteam.User.emailAddress}")
    
    0 讨论(0)
  • 2020-12-10 00:20

    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

    0 讨论(0)
提交回复
热议问题