grails - How to reuse custom validation logic in multiple fields from the same Domain -


i intend use custom validator check not null values in specific conditions in domain class. same check should run in more 1 field. "factored" validation closure , tried pass parameter each validator key in constraints clause.

string type string description string size  static constraints = {     description(nullable:true, validator: notnullifcustom)     size(nullable:true, validator: notnullifcustom) }  def notnullifcustom = { val, object ->         if (object.type == 'custom' && ! val)             return "must provide value field ${0} when type custom" } 

nevertheless, grails throws missingpropertyexception message 'no such property: notnullifcustom class... possible solutions: notnullifcustom'. if copy , paste closure body each validator entry inside constraints clause, runs expected.

ps: don't want use shared validator because i'm not sharing validator between domain classes, between fields within same domain.

the constraints block static, custom validators have too. change to

static notnullifcustom = { val, object ->    ... } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -