1
votes

Having the following commandobjects in Grails:

class commandA implements commandObjectType {
    String a

    static constraints = {
        a blank: false
    }
}

and

class commandB extends commandA {
    String b
}

How would one the implement custom field validation on b in the commandB object? It is to my knowledge not possible to override or in other ways change a closure..

Can this be done in anyway? I have tried "shifting" in a closure, without succes.. Is it possible to specify validators in-line with the fields in any way?

2

2 Answers

1
votes

I'm not sure if sharing contraints works for command objects, but you can try something like this:

class commandB extends commandA {
    String b

    static constraints = {
        importFrom commandA
    }
}

See the Grails documentation about constraints usage.

0
votes

Just define "constraints" block in commandB as usual with validation rules for "b" field. Validation should work for both "a" and "b" fields.