I am a newbie to Grails and would like to know how I can set a required field validation on Grails gsp or controller. For Example: if the user doesn't enter its username, then I should prompt a message saying
Username is required.
Where do I start?
Lookup Command objects: http://www.grails.org/Command+objects+and+Form+Validation
class MyController {
def myAction = { MyCommand cmd ->
if (cmd.hasErrors()) {
// do fail things
}
else {
// do success things
}
}
}
class MyCommand {
String username
static constraints = {
username(nullable:false, blank:false, minSize:4)
}
}