Reputation: 31
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?
Upvotes: 3
Views: 7348
Reputation: 4177
Add taglib for
<fs:localisedLink class="Button transp" elementId="voucherLink" mapping="voucherOffer">Gift Voucher</fs:localisedLink>
using exisitng logic for footer link
Upvotes: 0
Reputation: 2480
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.
Upvotes: 3
Reputation: 29
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)
}
}
Upvotes: 2