Questions tagged [grails-constraints]
23 questions
10
votes
3 answers
How to get value of a domain constraint in Grails?
I have a text field whose length I would like to limit at the maxSize constraint of one of my domain classes.
So if I have a class foo:
class Foo {
String bar
static constraints = {
bar(maxSize: 100)
}
}
I would like to get…

Igor
- 33,276
- 14
- 79
- 112
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…

Alexandre Bourlier
- 3,972
- 4
- 44
- 76
6
votes
2 answers
Grails Scaffolding - define possible values for this property of a domain class
I am new to Grails. I have a Person domain class as :
class Person {
String firstName
String lastName
String gender
Date dateOfBirth
}
And wondering if I can define possible values for a property - say gender as {M, F, U} so that…

gtiwari333
- 24,554
- 15
- 75
- 102
4
votes
1 answer
How to escape forward slash in the matches constraint
How can I escape the forward slashes in the regex when using the matches constraint? This is what I tried:
constraints {
url (
matches: "^http://www.google.com/$"
)
}
Error: solution: either escape a literal dollar sign "\$5" or…

zoran119
- 10,657
- 12
- 46
- 88
3
votes
5 answers
How to set uniqueness at DB level for a one-to-many association?
My problem is simple but I could not find any GORM syntax for this.
Consider the following class:
class Article {
String text
static hasMany = [tags: String]
static constraints= {
tags(unique: true) //NOT WORKING
}
}
I want to have…

fabien7474
- 16,300
- 22
- 96
- 124
2
votes
2 answers
regex validation - grails
im pretty new in grails.. im having a little problem right now on validation using matches. What I wanted to happen is that a field can accept combination of alphanumeric and special characters, letters only and numbers only, and if the user inputs…

antibry
- 282
- 5
- 22
2
votes
4 answers
Grails unit test for domain class insertBefore
How can I test the initBefore method of Groovy Domain-Classes with a unit test in Grails?
I created the dummy object but the beforeInsert-method is not called until myObject.save() is invoked and save is unavailable in the testing…

LukeSolar
- 3,795
- 4
- 32
- 39
2
votes
3 answers
Grails i18 message properties
I want to change the default message for typemismatch.java.math.BigDecimal in i18 message properties file for different properties.
In the documentation it says, use typeMismatch.$className.$propertyName to customize but that does not work for…

user741701
- 33
- 3
2
votes
0 answers
Grails Unit testing GORM global constraints
I have an issue where the global constraints setup in the Config are not working when running unit tests.
This is in my Config.groovy:
grails.gorm.default.constraints={
'*'(nullable:true, bindable:true)
}
in my test I have tried this:
static…

Kevin Paxton
- 21
- 4
1
vote
2 answers
grails validation using matches constraints - regex
Im really having a hard time in matches constraints in grails, im pretty new in it. what i wanted my field to only accept is an input with a format of a phone number, like 02-3546352 where (Area Code)-(Telephone Number). where other characters…

antibry
- 282
- 5
- 22
1
vote
2 answers
regex validation - grails constraints
I'm pretty new on grails, I'm having a problem in matches validation using regex. What I wanted to happen is my field can accept a combination of alphanumeric and specific special characters like period (.), comma (,) and dash (-), it may accept…

antibry
- 282
- 5
- 22
1
vote
1 answer
Make inherited constraints stricter
In Grails when using CommandObjects or DomainClass how can I restrict a constraint of an inherited property?
Say I have a parent class with non-null property payload:
abstract class TextContentCommand extends ContentCommand {
String payload
…

Amio.io
- 20,677
- 15
- 82
- 117
1
vote
1 answer
Can one constraint on a command object check the result of another?
This is a simple example that doesn't work, I'm wondering if there is a way to validate a inside the validator block of b if it hasn't already been validated.
Example how I thought it would work:
static constraints =
{
a nullable: false
b…

Lifeweaver
- 986
- 8
- 29
1
vote
1 answer
constraints in grails
Hi I am having some trouble getting my constraints to work in my grails project. I am trying to just make sure that the field for Site_ID is not left blank but it still accepts an blank input. Also I am trying to set the order in which the fields…

Ameya
- 549
- 1
- 10
- 19
0
votes
1 answer
Grails Constraints with Java Classes and Hibernate Mappings
I have the following Java class defined in src/java
package org.davisworld.trip;
public class AirportHbm {
private long id;
private String name;
private String iata;
private String state;
private String lat;
private String lng;
//…

Vito Andolini
- 425
- 1
- 5
- 14