Quantcast

How to render error message, along with Spring Security?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to render error message, along with Spring Security?

user12345
Hi all, I'm very new t Grails. I have certain problem in understanding spring security plugin and how custom error message works.

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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to render error message, along with Spring Security?

bhushan154
In the grails-app\i18n\messages.properties, just add the following line:

user.username.unique=Username already exists. Please use other username.

Let me know if this works for you. If not I can upload a sample app.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to render error message, along with Spring Security?

bhushan154
In reply to this post by user12345
I created a project for your reference. Hope it is helpful.

Cheers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to render error message, along with Spring Security?

user12345
Can you provide me the link?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to render error message, along with Spring Security?

bhushan154
Forgot to press the Upload button after selecting the file :)

Attached.

messages.zip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to render error message, along with Spring Security?

ludachrispeed
It looks like you wrote a new message for when the uniqueness constraint is violated, but the error you were getting (Property [{0}] of class [{1}] cannot be null) was not a uniqueness problem - it was a something-was-null problem.  That error got associated with the default.null.message (as it should) instead of your user.username.unique message.

Maybe the User instance you created didn't set the password or the email?

Chris

2012/8/7 bhushan154 [via Grails] <[hidden email]>
Forgot to press the Upload button after selecting the file :)

Attached.

messages.zip


If you reply to this email, your message will be added to the discussion below:
http://grails.1312388.n4.nabble.com/How-to-render-error-message-along-with-Spring-Security-tp4632771p4632783.html
To start a new topic under Grails - user, email [hidden email]
To unsubscribe from Grails - user, click here.
NAML

Loading...