3
votes

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?

3

3 Answers

2
votes

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)
    }
}
2
votes

You could do it in your GSP. For example:

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

Here, required=true ensures that you enter something in the field before submitting the form.

0
votes

Add taglib for

                    <fs:localisedLink class="Button transp"  elementId="voucherLink" mapping="voucherOffer">Gift Voucher</fs:localisedLink>

using exisitng logic for footer link