I'm having trouble to bind values using a transient property using grails 3.1.4.
Taking this domain as an example:
class Domain {
Boolean b1
Boolean b2
Boolean b3
void setPropertyList(propertyList) {
if(propertyList.contains('someValue'))
this.b1 = true
}
static transients = ['propertyList']
static constraints = {
propertyList bindable: true
}
}
I would like to use a specific property (here: propertyList
) for data binding. This property is available in the data binding source, but not in my domain. So I added a transient and a setter. To include the transient propertyList
for data binding I added the bindable
constraint.
The setter setPropertyList
is called during data binding. The properties of the resulted domain instance has all properties set as expected.
But when I try to save the resulted instance I get the following exception:
groovy.lang.GroovyRuntimeException: Cannot read write-only property: propertyList
at org.grails.validation.ConstrainedPropertyBuilder.doInvokeMethod(ConstrainedPropertyBuilder.java:74)
Looks like grails having some trouble to validate the instance.
Any ideas how to fix this?
After some debugging it turns out, that grails couldn't find a type for propertyList
and so skips the data binding.
Adding a getter helps grails to infer the type. This avoids the exception.
List<String> getPropertyList() {}