Mandatory field check in rake

I am new to Grails and would like to know how I can set the required field check on gsp or the Grails controller. For example: if the user does not enter his username, I must request a message

Username required.

Where to begin?

+3
source share
3 answers

This guide discusses the user guide in detail. See
http://docs.grails.org/latest/guide/validation.html

+4
source

Search for 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)
    }
}
+2
source

GSP. :

<g:textField name="username" required="true" value="${user?.login}"></g:textField>

required = true , - .

+2

Source: https://habr.com/ru/post/1762698/


All Articles