List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(owningClass, requestParams, sectionCrumbs, pathVars);
ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
// Only get collection property metadata when there is a non-structured content field that I am looking for
Property collectionProperty = null;
FieldMetadata md = null;
if (!collectionField.contains("|")) {
collectionProperty = mainMetadata.getPMap().get(collectionField);
md = collectionProperty.getMetadata();
ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
}
ppr.addFilterAndSortCriteria(getCriteria(requestParams));
ppr.setStartIndex(getStartIndex(requestParams));
ppr.setMaxIndex(getMaxIndex(requestParams));
ppr.removeFilterAndSortCriteria("requestingEntityId");
ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
ppr.addCustomCriteria("owningClass=" + owningClass);
modifyFetchPersistencePackageRequest(ppr, pathVars);
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = null;
// If we're dealing with a lookup from a dynamic field, we need to build the list grid differently
if (collectionField.contains("|")) {
listGrid = formService.buildMainListGrid(drs, mainMetadata, "/" + owningClass, sectionCrumbs);
listGrid.setListGridType(ListGrid.Type.TO_ONE);
listGrid.setSubCollectionFieldName(collectionField);
listGrid.setPathOverride("/" + owningClass + "/" + collectionField + "/select");
md = new BasicFieldMetadata();
md.setFriendlyName(mainMetadata.getPolymorphicEntities().getFriendlyName());
collectionProperty = new Property();
collectionProperty.setMetadata(md);
} else if (md instanceof BasicFieldMetadata) {
listGrid = formService.buildCollectionListGrid(null, drs, collectionProperty, owningClass, sectionCrumbs);
}
model.addAttribute("listGrid", listGrid);