StructuredBindingEditors convert structured data in a Map into an object. Typically a structured editor will pull several values out of the Map that are necessary to initialize the state of the object.
class Address { String state String city } class StructuredAddressBindingEditor implements StructuredBindingEditor { public Object getPropertyValue(Object obj, String propertyName, Mapsource) { def address = new Address() address.state = source[propertyName + '_someState'] address.city = source[propertyName + '_someCity'] address } } def binder = new SimpleDataBinder() binder.registerStructuredEditor Address, new StructuredAddressBindingEditor() def resident = new Resident() def bindingSource = [:] bindingSource.name = 'Scott' bindingSource.homeAddress_someCity = "Scott's Home City" bindingSource.homeAddress_someState = "Scott's Home State" bindingSource.workAddress_someState = "Scott's Work State" bindingSource.workAddress = 'struct' bindingSource.homeAddress = 'struct' binder.bind resident, bindingSource resident.name == 'Scott' resident.homeAddress assert resident.homeAddress.city == "Scott's Home City" assert resident.homeAddress.state == "Scott's Home State" assert resident.workAddress assert resident.workAddress.state == "Scott's Work State" assert resident.workAddress.city == null
Methods inherited from class | Name |
---|---|
interface grails.databinding.StructuredBindingEditor |
grails.databinding.StructuredBindingEditor#getPropertyValue(java.lang.Object, java.lang.String, grails.databinding.DataBindingSource) |
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |