Vote count:
0
I'm modifying grails i18nFields plugin to make i18n fields validation more flexible. Currently this plugin makes copy of each i18n field for every locale, and it copies constraints.
So AST transformation turns class
@I18nFields
class Country {
String name
String capitalName
static constraints = {
name blank:false, nullable: false
capitalName blank:false, nullable: false
}
static i18nFields = ['name', 'capitalName']
}
turns into somesthing effectively like this:
@I18nFields
class Country {
String name
String capitalName
static transients = ['name', 'capitalName']
String name_en_US
String name_es_ES
String capitalName_en_US
String capitalName_es_ES
static constraints = {
name_en_US blank:false, nullable: false
name_es_ES blank:false, nullable: false
capitalName_en_US blank:false, nullable: false
capitalName_es_ES blank:false, nullable: false
}
static i18nFields = ['name', 'capitalName']
}
So instaces of Country must be fully valid for every locale registered in plugin configuration. What I want to achieve is to be able to set different i18n fields validation strategy to different domain classes: 1) All i18n fields must be valid for every locale (current behavior) 2) One locale must be fully valid, for each of the rest locales either all of the i18n fields are null or all of them are valid. 3) More compicated strategies may emerge later
To achieve this, I'm going to subclass HibernateDomainClassValidator and override postValidate method to handle i18n fields differently. And then register this subclass as validator bean for every domain class that has i18n fields.
The problem is that in case of cascading validation of classes like
class User {
//Some fields
Country country
}
country's fields are validated by user's domain class validator, and validation fails. CountryValidator's methoads are not executed at all.
So it seems that to achieve my task, I have to rewrite whole GrailsDomainClassValidator to change cascading validation.
My question is: is there any simpler solution?
Aucun commentaire:
Enregistrer un commentaire