agileaholic :)

Grails Constraints

Posted in agile, grails, groovy by Prabhu Beeman on January 20, 2010

Consider the following domain
class User {
    String name,
    String email,
    String password

    static constraints = {
       password(size:6..32,blank:false),
       email(blank:false,email:true)
    }
}

Is there a way where I can validate only my password?
YES

if(user.hasErrors()) {
    if(user.errors.hasFieldErrors(“password”)) {
       println user.errors.getFieldError(“password”).rejectedValue
    }
}

Advertisement
Tagged with:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.