Questions tagged [grails-validation]

Grails validation capability is built on Spring’s Validator API and data binding capabilities. However Grails takes this further and provides a unified way to define validation "constraints" with its constraints mechanism.

Docs: https://docs.grails.org/latest/guide/validation.html

Famous question: Grails domain class: unique constraint for multiple columns

84 questions
53
votes
1 answer

Grails domain class: unique constraint for multiple columns

Suppose a simple Grails domain class: class Account { String countryId; String userName; String password; static constraints = { ...???... } } It is required that user names are unique for a particular countryId, thus…
15
votes
2 answers

Displaying Grails Field Errors

Does anybody know how I could get the fieldError to print out in the example below. for each item with an error, I would like to print custom error messages that I have defined in the messages.properties file at the moment all this does is print the…
mh377
  • 1,656
  • 5
  • 22
  • 41
13
votes
2 answers

How can I override the default error message in Grails?

I have a Person object with a lastName field. The lastName field cannot be blank. When the user submits a form blank value in the lastName field, the error message that the user sees is: Property [lastName] of class [com.example.Person] cannot be…
Spike Williams
  • 35,795
  • 13
  • 48
  • 60
13
votes
5 answers

Grails Problem with custom error messages

I am currently trying to specify custom error messages in grails for the default constraints but so far all I get back is the default error message. I know that I have to edit the grails-app/i18n/messages.properties file If I change the following…
mh377
  • 1,656
  • 5
  • 22
  • 41
10
votes
2 answers

Grails: nested command objects

In my grails app I have an outer command object that contains a list of other command objects: public class OuterCommand { List innerCommands = ListUtils.lazyList([], FactoryUtils.instantiateFactory(InnerCommand)) } class…
Dónal
  • 185,044
  • 174
  • 569
  • 824
9
votes
1 answer

Grails min constraint for date validation

I am a newbie in grails and groovy. I have a Project domain-class with start and end date. I want to put in a constraint specifying that the end date needs to be greater than the start date(and then further another child object of project needs to…
Ravindra Sane
  • 472
  • 3
  • 10
8
votes
1 answer

What is the connection between validate() and hasErrors()

This question comes from the problem of another question of mine. In that question, I come across a situation that hasErrors() function doesn't work for non-persistent domain class, even after all the things I did following the instruction, part 7.5…
Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
7
votes
2 answers

Rendering command validation errors across a redirect

I cannot render the errors from my command object. It does the job well but my .gsp view does not render the errors I raise. Here is my controller action: def handleModifyProfile2 = { CreditProviderModificationCommand cpmc -> // bind params to the…
7
votes
2 answers

Grails: can I make a validator apply to create only (not update/edit)

I have a domain class that needs to have a date after the day it is created in one of its fields. class myClass { Date startDate String iAmGonnaChangeThisInSeveralDays static constraints = { iAmGonnaChangeThisInSeveralDays(nullable:true) …
Mikey
  • 4,692
  • 10
  • 45
  • 73
7
votes
2 answers

custom Grails validation

Normally for a Grails domain or command class, you declare your constraints and the framework adds a validate() method that checks whether each of these constraints is valid for the current instance e.g. class Adult { String name Integer age …
Dónal
  • 185,044
  • 174
  • 569
  • 824
7
votes
2 answers

Grails client side validation

How do you (if you) manage client side validation with grails ? Do you use a plugin or do you mirror your constraints using a javascript framework ? Cheers
user217975
7
votes
3 answers

grails validate nested command object not working

I'm using grails 2.2.1 and attempting to validate a nested command structure. Here is a simplified version of my command objects: @Validateable class SurveyCommand { SectionCommand useful SectionCommand recommend SurveyCommand() { …
Chris Montgomery
  • 2,344
  • 2
  • 19
  • 30
7
votes
2 answers

Grails conditional nullable validation or custom validator with nullable option

I have a form to create a place. Depending of the country, the province (state, region) field is required or not. When is not required, I want to be null, not empty string. I have code that makes all empty form fields, null: def newparams = [:] …
Eduard
  • 3,536
  • 1
  • 20
  • 27
6
votes
2 answers

parameterized Grails validation messages

In the messages.properties file in a Grails application I've seen examples of validation messages such as: User.password.size=Size of bar must be between {0} and {1} which applies to class User { String password static constraints = { …
Dónal
  • 185,044
  • 174
  • 569
  • 824
5
votes
2 answers

Grails domain class constraints for relation between fields

I need to write Domain class constraint in Grails which says that one integer field must be greater or equal than the other. When I write the code like this: class MyDomain { String title int valueMin = 1 int valueMax = 1 static constraints =…
Pavel P
  • 637
  • 1
  • 7
  • 21
1
2 3 4 5 6