We have a presentation template that has been associated with all the channel pages in our wem 8.1 environment. All the regions and content components except one are are template scoped and set from the template.
There is one region in the template which is page scoped and are supposed to be set from page. When we set the display view of the component associated with page scoped region from the floatie tools available on the preview page, it works fine. When we programmatically try to set the display view of the same component, it sets that display view to all the pages associated with the same template.
Can you please look into this issue?
The method that is setting the display view is here:
__________________________________Start of the method__________________________________
public static void setDisplayView(Page page, String displayViewId) throws ApplicationException, AuthorizationException, ValidationException, RemoteException{
ManagedObjectVCMRef[] moVCMRef = ManagedObject.getReferredManagedObjects(page.getContentManagementId());
ManagedObject managedObject = null;
for (int j = 0; j < moVCMRef.length; j++) {
managedObject = moVCMRef[j].retrieveManagedObject(RequestParameters.getImmutableInstanceFullRelation());
//ManagedObject mo = Region.findByContentManagementId(new ManagedObjectVCMRef(regionId));
if (managedObject instanceof Template ) {
Template template = (Template) managedObject;
ManagedObjectVCMRef[] moVCMRefTemp = ManagedObject.getReferredManagedObjects(template.getContentManagementId());
for (int i = 0; i < moVCMRefTemp.length; i++) {
ManagedObject managedObjectReg = moVCMRefTemp[i].retrieveManagedObject(RequestParameters.getImmutableInstanceFullRelation());
if (managedObjectReg instanceof Region) {
Region region = (Region) managedObjectReg;
if (region.getName().equalsIgnoreCase("Region Content")) {
ManagedObjectVCMRef[] moVCMRefComponents = ManagedObject.getReferredManagedObjects(region.getContentManagementId());
//List components = region.getConfiguredContentComponents();
ManagedObject moComp = null;
for (int k = 0; k < moVCMRefComponents.length; k++) {
moComp = moVCMRefComponents[k].retrieveManagedObject(RequestParameters.getImmutableInstanceFullRelation());
if (moComp instanceof ContentComponent) {
ContentComponent contentComponent = (ContentComponent) moComp;
contentComponent.setAttributeValue("vgnExtTemplatingComponentDisplayViewId", displayViewId);
//region.setAttributeValue("regionComponentId", value)
page.setRegion(region);
page.setManagedObjectStatus(ManagedObjectStatus.APPROVED);
page.commit();
System.out.println("Display view is set.");
}
}
}
}
}
}
}
}
___________________________________End of the Method_____________________________________
Please note that we are programmatically setting the template and page layout to the channel pages and they are working as expected.
Please let us know if you need anything else.