Monday, May 20, 2013

Groovy Grails Domain GORM and enum types


Create an enum class in src/groovy or src/java.

/**
 * User: pritom
 */
public enum UserStatus {
    active('active'),
    on_hold('on_hold')

    String name

    UserStatus(String name) {
        this.name = name
    }

    public String getName() {
        name
    }

    public String toString() {
        return this.getName()
    }
}

Specify a property in your domain class with the enum type.

class User {
 String userName,
 UserStatus type = UserStatus.active
}

No comments:

Post a Comment