grails-validation

Grails Problem with custom error messages

北战南征 提交于 2019-12-03 02:16:35
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 default error codes message, it will correctly display the new error message default.blank.message=Property [{0}] of class [{1}] cannot be blank However, this is not what I am trying to do. I need more granular error reporting and have more than one field that can be blank etc. What I would like to be able to do would be, display custom messages for

Grails validateable not work for non-persistent domain class

↘锁芯ラ 提交于 2019-12-02 10:27:20
问题 I followed the instruction here: http://www.grails.org/doc/latest/guide/7.%20Validation.html and added into config.groovy : grails.validateable.classes = [liningtest.Warm'] Then added in src/groovy/Warm.groovy (it's a non-persistent domain class): package liningtest import org.codehaus.groovy.grails.validation.Validateable class Warm { String name; int happyCite; Warm(String n, int h) { this.name = n; this.happyCite = h; } static constraints = { name(size: 1..50) happyCite(min: 100) } } But

Grails get session variable from domain validator

為{幸葍}努か 提交于 2019-12-02 10:27:13
问题 Im sure this is a common scenario, but I haven't found any answers. I have a session-scoped variable that holds the currently signed in user and I need to perform conditional validation by way of a custom validator in a domain object. Is there a way to get the the current user from the session scope while in a validator, or is there perhaps another way to do this, keeping in mind that I want to be able to return the errors for specific fields from my validator(e.g. if(isBlank(it))return [

Grails min constraint for date validation

爱⌒轻易说出口 提交于 2019-12-01 15:55:25
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 have its startdate and enddate validate with the parent Project's dates). Is this possible with the min constraint or do I have to put it elsewhere? Unique constraint does allow two properties to be linked that way, hoping min/max constraints allow that. I have tried startDate(blank:false) endDate(blank:false, min:'startDate') It throws an error

Grails min constraint for date validation

流过昼夜 提交于 2019-12-01 14:39:57
问题 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 have its startdate and enddate validate with the parent Project's dates). Is this possible with the min constraint or do I have to put it elsewhere? Unique constraint does allow two properties to be linked that way, hoping min/max constraints allow

Grails domain class: unique constraint for multiple columns

偶尔善良 提交于 2019-11-28 20:03:48
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 there must be a unique contraint on two columns. How to express this in the constraints definition? userName(unique: ['countryId']) You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on the username. So, for example if you wanted to make userName unique within a countryId and provinceId it

Grails domain class: unique constraint for multiple columns

扶醉桌前 提交于 2019-11-27 12:40:34
问题 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 there must be a unique contraint on two columns. How to express this in the constraints definition? 回答1: userName(unique: ['countryId']) You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on