2020 Oct 10 2:43 PM - edited 2024 Feb 03 7:00 PM
Hybris version 2005.4
We have incorporated the CMS Item API for a custom CMS Item, to persist and render it in SmartEdit. There is a many-to-many relation of this item with another item and both source and target element have collectiontype="set" in the relation. In this relation our custom item is the target element and hence the getters and setters for the related item is on the custom item/target element, that accepts and returns a Set.
Here is the code flow from the CMS Item API documentation, I have highlighted the key methods -

The issue that we are facing is, the collection (Set of source item in the relation) attribute, is not persisting when the custom CMS Item is saved. The root cause is the convertRepresentationToAttributeValue() always returns an ArrayList value which is then used in the setAttributeValue() method to set it on the custom item model using reflection. But, since the attribute setter on the item model expects a Set as a parameter and not an ArrayList, the value setter fails.
We modified the relation setup and removed collectiontype="set" (default collectiontype is Collection) and that fixes the problem, as it updates the getter and setter on the item model to accept and return a Collection, which works fine in the above mentioned CMS Item persistence methods.
Is there a way by which the attribute can be persisted for the item with the collection type as Set on the relation?
We know that we can create a custom populator and add it in "cmsContentItemTypePopulatorsMap" but that does not seem to be an optimal solution. Also, with that we will need to add the same populator for all the other items that have this custom item associated as an attribute.
Thanks !
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.