Collection in items.xml

In hybris we use collection to represent a group of objects. Basically, CollectionTypes are based on the Java Collection class.

Basic Terms/Keywords of Collection in there definition :

Example of collectiontype tag in *-items.xml  file : 

 <collectiontype code="EntryGroupNumbersList" elementtype="java.lang.Integer" autocreate="true" type="set"/>

Terms :

code : This actually defines the name of the collection that will be used as type for the item attribute tag.

elementtype : This is used to define what type of value this collection will store, either atomic (String, Number etc) or existing item type (User, Address etc).

autocreate :  By providing autocreate as true, we say to the hybris system to create a collection type.

type : This is used to define a type of collection like set, list etc. If we don't provide a type, then by default, this will create a collection type.

To use a new collection we need to follow two steps in hybris.

1. Define a collection

2. Utilize the defined collection in item definition

1. Define a collection :

1.1 Collection of atomic type :  In hybris we have OOTB already lot's of atomic type are avilable as String ,Number ,Long, Boolean etc. by using we can create collection :
               <collectiontype code="EntryGroupNumbersList" elementtype="java.lang.Integer" autocreate="true" type="set"/>

1.2 Collection of existing item type : In hybris we have option to create a collection of custome objects(item type) like in      NavigationBarCollectionComponent item type we find navigationBarComponentList collection

<collectiontype code="navigationBarComponentList"
			elementtype="NavigationBarComponent" autocreate="true" generate="true"
			type="list" />
Note : Here used NavigationBarComponent  is already existing item type (If you used any other item, make sure it must be an existing one otherwise can be face build issue)

2. Utilize the defined collection in item definition :

Once created a new collection then now need to use this or inject this collection in required item type as :

creation of required collection :

<collectiontype code="navigationBarComponentList"
			elementtype="NavigationBarComponent" autocreate="true" generate="true"
			type="list" />

Injection of created collection in item type : 

<itemtype code="NavigationBarCollectionComponent"
				autocreate="true" generate="true" extends="SimpleCMSComponent"
				jaloclass="de.hybris.platform.acceleratorcms.jalo.components.NavigationBarCollectionComponent">
				<description>Deprecated since 6.2, please use NavigationComponent instead. It represents account navigation bar component that contains cms navigation node.</description>
				<attributes>
					<attribute qualifier="components" type="navigationBarComponentList">
						<persistence type="property" />
						<modifiers />
						<description>A collection of navigation bar components</description>
					</attribute>
				</attributes>
			</itemtype>

Leave a comment