if (p != null && p.getMetadata() instanceof AdornedTargetCollectionMetadata) {
// Because we're dealing with a nested adorned target collection, this particular request must act
// directly on the first adorned target collection. Because of this, we need the actual id property
// from the entity that models the adorned target relationship, and not the id of the target object.
Property alternateIdProperty = entity.getPMap().get(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
DynamicResultSet drs = service.getRecordsForCollection(cmd, entity, p, null, null, null,
alternateIdProperty.getValue(), sectionCrumbs).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(alternateIdProperty.getValue(), drs, p,
ppr.getAdornedList().getAdornedTargetEntityClassname(), sectionCrumbs);
listGrid.setListGridType(ListGrid.Type.INLINE);
listGrid.getToolbarActions().add(DefaultListGridActions.ADD);
entityForm.addListGrid(listGrid, EntityForm.DEFAULT_TAB_NAME, EntityForm.DEFAULT_TAB_ORDER);
} else if (p != null && p.getMetadata() instanceof MapMetadata) {
// See above comment for AdornedTargetCollectionMetadata
MapMetadata mmd = (MapMetadata) p.getMetadata();
Property alternateIdProperty = entity.getPMap().get(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
DynamicResultSet drs = service.getRecordsForCollection(cmd, entity, p, null, null, null,
alternateIdProperty.getValue(), sectionCrumbs).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(alternateIdProperty.getValue(), drs, p,
mmd.getTargetClass(), sectionCrumbs);
listGrid.setListGridType(ListGrid.Type.INLINE);