use of grails.databinding.CollectionDataBindingSource in project grails-core by grails.
the class DataBindingUtils method bindToCollection.
/**
* For each DataBindingSource provided by collectionBindingSource a new instance of targetType is created,
* data binding is imposed on that instance with the DataBindingSource and the instance is added to the end of
* collectionToPopulate
*
* @param targetType The type of objects to create, must be a concrete class
* @param collectionToPopulate A collection to populate with new instances of targetType
* @param collectionBindingSource A CollectionDataBindingSource
* @since 2.3
*/
public static <T> void bindToCollection(final Class<T> targetType, final Collection<T> collectionToPopulate, final CollectionDataBindingSource collectionBindingSource) throws InstantiationException, IllegalAccessException {
final GrailsApplication application = Holders.findApplication();
PersistentEntity entity = null;
if (application != null) {
try {
entity = application.getMappingContext().getPersistentEntity(targetType.getClass().getName());
} catch (GrailsConfigurationException e) {
// no-op
}
}
final List<DataBindingSource> dataBindingSources = collectionBindingSource.getDataBindingSources();
for (final DataBindingSource dataBindingSource : dataBindingSources) {
final T newObject = targetType.newInstance();
bindObjectToDomainInstance(entity, newObject, dataBindingSource, getBindingIncludeList(newObject), Collections.emptyList(), null);
collectionToPopulate.add(newObject);
}
}
use of grails.databinding.CollectionDataBindingSource in project grails-core by grails.
the class DataBindingUtils method bindToCollection.
public static <T> void bindToCollection(final Class<T> targetType, final Collection<T> collectionToPopulate, final ServletRequest request) throws InstantiationException, IllegalAccessException {
final GrailsApplication grailsApplication = Holders.findApplication();
final CollectionDataBindingSource collectionDataBindingSource = createCollectionDataBindingSource(grailsApplication, targetType, request);
bindToCollection(targetType, collectionToPopulate, collectionDataBindingSource);
}
Aggregations