Hi 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 Eaxmple , if the user doest enter the user name then I should promt a message saying user name is required.
Thanks sam
Hi 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 Eaxmple , if the user doest enter the user name then I should promt a message saying user name is required.
Thanks sam
The user manual discusses this extensively. See http://grails.org/doc/latest/guide/7.%20Validation.html
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)
}
}