I have a domain class :
package x
class User {
transient springSecurityService
String username
String password
//other stuffs.
static constraints = {
username blank: false, unique: true
password blank: false
email blank: false, email:true
}
}
This is the class that I used for Spring security. In my /register/index page I need custom error messages, so I added these lines into message.properties:
x.User.username.unique=Username already exists. Please use other username.
But that doesn’t seem to be working. I get only this error message :
Property [{0}] of class [{1}] cannot be null
Even though I pass some value into my username column I still get this error message. I’m confused with it. How this /register/index comes from?
Where I need to change the error message?
Thanks in advance.
The problem is the way you’ve declarated the message code, it doesn’t fallow the convention. Take a look Validation and Internationalization. Here you can find that the right way is
[Class Name].[Property Name].[Constraint Code]So your constraint should be