Items.xml
* Items.xml file is used for data modeling in hybris.
* In items.xml file, we can define new types or extend existing types.
* we can also define, override, and extend attributes .
* The order of the items.xml file is given below,
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="items.xsd">
<atomictypes>
...
</atomictypes>
<collectiontypes>
...
</collectiontypes>
<enumtypes>
...
</enumtypes>
<maptypes>
...
</maptypes>
<relations>
...
</relations>
<itemtypes>
...
</itemtypes>
</items>
|
* The items.xml file is validated against an XSD file ( items.xsd ),So the order of type definitions must define in the above order.
====================================================================================
Here is given examples on how to define the collection types, relation types, item types, map types and a simple task on how to show in the storefront.
Step 1:-
* Goto items.xml file as follow
(/home/HybrisWorks/hybris/hybris/bin/custom/resources/**-items.xml) and type code like the following.. and also craete corresponding items
For collections Type
<collectiontypes>
<collectiontype code="GenderList" elementtype="Gender" autocreate="true" generate="true" type="list" />
<collectiontype code="SwatchColorSet" elementtype="SwatchColorEnum"
autocreate="true" generate="true" type="set" />
<collectiontype elementtype="java.lang.String" code="ProductList"
autocreate="true" generate="true" type="list" />
<collectiontype elementtype="media" code="ImagesList"
autocreate="true" generate="true" type="list" />
</collectiontypes>
|
Relations:
<relations>
<relation code="Company2Employees" generate="true" localized="false" autocreate="true">
<sourceElement type="Company1" cardinality="one" qualifier="company1">
<modifiers read="true" write="true" search="true" optional="false" />
</sourceElement>
<targetElement type="Employees1" cardinality="many" qualifier="employees1" ordered="true">
<modifiers read="true" write="true" search="true" optional="true" partof="true" />
</targetElement>
</relation>
</relations>
|
Enum Types:-
<enumtypes>
<enumtype generate="true" code="SwatchColorEnum" autocreate="true" dynamic="true">
<value code="BLACK" />
<value code="BLUE" />
<value code="BROWN" />
<value code="GREEN" />
<value code="GREY" />
<value code="ORANGE" />
</enumtype>
<enumtype code="genders" autocreate="true" generate="true">
<value code="MALE" />
<value code="FEMALE" />
</enumtype>
</enumtypes>
|
Map Types:-
<maptypes>
<maptype code="cityNamesMap" argumenttype="java.lang.String"
returntype="java.lang.String" autocreate="true" generate="true" />
</maptypes>
|
Items Types:-
<typegroup name="Employees">
<itemtype code="Employees1" extends="SimpleCMSComponent"
autocreate="true" generate="true" jaloclass="com.bajaj.core.jalo.Employees1">
<attributes>
<attribute type="java.lang.String" qualifier="employeeName">
<persistence type="property"></persistence>
</attribute>
<attribute type="java.lang.Integer" qualifier="experience"
<persistence type="property"></persistence>
</attribute>
</attributes>
</itemtype>
</typegroup>
|
Step 2:-
* perform ant clean all and Star server by using command . ./hybrisserver.sh debug
Step 3:-
* Goto(https://bajaj.local:9002) hac login with username (admin) and password (nimda) then goto platform click on Update it will be updated.
* Then you will get like below
* select Platform and click on Update
Step 4:-
* Goto cms-content.impex file (/bajajinitialdata/resources/**initialdata/import/sampledata/contentCatalogs/bajajContentCatalog/cms-content.impex)
* write code like this for Collection types items types ,Enum types ,Map types,Relations
Relations :-
#books component
############## target #########################
INSERT_UPDATE Employees1;$contentCV[unique=true];uid[unique=true];name;employeeName;experience;company1(uid,$contentCV)
;;Employees1;Employees 1;Naresh;1;Company1
;;Employees2;Employees 1;Satish;4;Company1
;;Employees3;Employees 1;Viswa;10;Company1
#################### source component #########################
INSERT_UPDATE Company1;$contentCV[unique=true];uid[unique=true];name;companyName;companyLocation;&componentRef
;;Company1;company 1;Google;hydrabad;Company1
INSERT_UPDATE ContentSlot;$contentCV[unique=true];uid[unique=true];cmsComponents(&componentRef)
;;Company1ContentSlot;Company1,bajajFooterComponent
INSERT_UPDATE ContentSlotForPage;$contentCV[unique=true];uid[unique=true];position[unique=true];page(uid,$contentCV)[unique=true][default='homepage'];contentSlot(uid,$contentCV)[unique=true];;;
;;Company1Contentslotforpage1;Company1;;Company1ContentSlot
Items Type,Collection type,Enum types,MapTypes:
############## Electronics component ################
# CMSParagraphComponents
INSERT_UPDATE CMSParagraphComponent;$contentCV[unique=true];uid[unique=true];name;&componentRef;content;;;
;;ElectronicsParagraphComponent1;Electronics Paragraph Component;ElectronicsParagraphComponent1;CMS Paragraph Component "welcome to BajajElectronics"
;;ElectronicsParagraphComponent2;Electronics Paragraph Component1;ElectronicsParagraphComponent2;welcome to BajajElectronics
#Custom component
INSERT_UPDATE ElectronicComponent;$contentCV[unique=true];uid[unique=true];name;images(&mediaRef);productNames;paragraph(&componentRef);gendarColumn(code);colors(code);usercity[map-delimiter=,][key2value-delimiter=->][mode=append];&componentRef
;;ElectronicComponent;Electronic Component;mediaimage,mediaimage4,mediaimage5,mediaimage8;Mobiles,TV,Shoes,Laptops,Toys,Accesaries,HomeNeeds;ElectronicsParagraphComponent1;;"BLACK";"hari->hyd,manu->blr";ElectronicComponent
#ContentSlot
INSERT_UPDATE ContentSlot;$contentCV[unique=true];uid[unique=true];name;active;cmsComponents(&componentRef);;;
;;ElectronicContentSlot;Electronic Content Slot;true;ElectronicComponent
# ContentSlotForPage
INSERT_UPDATE ContentSlotForPage;$contentCV[unique=true];uid[unique=true];position[unique=true];page(uid,$contentCV)[unique=true][default='homepage'];contentSlot(uid,$contentCV)[unique=true];;;
;;ElectronicContentSlotForPage;ElectronicComponent;;ElectronicContentSlot
#for Images
INSERT_UPDATE Media;$contentCV[unique=true];code[unique=true];realfilename;@media[translator=de.hybris.platform.impex.jalo.media.MediaDataTranslator];mime[default='image/jpeg'];altText;folder(qualifier)[default='images'];&mediaRef
;;mediaimage1;cam1.jpeg;$siteResource/image/cameras/cam1.jpeg;image/jpeg;hybris Accelerator;;mediaimage1
;;mediaimage2;cam3.jpeg;$siteResource/image/cameras/cam3.jpeg;image/jpeg;hybris Accelerator;;mediaimage2
;;mediaimage;Lg.jpeg;$siteResource/image/TV/Lg.jpeg;image/jpeg;hybris Accelerator;;mediaimage
;;mediaimage4;trims.jpg;$siteResource/image/trims.jpg;image/jpg;hybris Accelerator;;mediaimage3
;;mediaimage5;samsung.jpeg;$siteResource/image/TV/samsung.jpeg;image/jpeg;hybris Accelerator;;mediaimage4
;;mediaimage6;samsung1.jpeg;$siteResource/image/TV/samsung1.jpeg;image/jpeg;hybris Accelerator;;mediaimage5
;;mediaimage7;vu.jpeg;$siteResource/image/TV/vu.jpeg;image/jpeg;hybris Accelerator;;mediaimage8
;;mediaimage8;PC.jpg;$siteResource/image/PC.jpg;image/jpg;hybris Accelerator;;mediaimage6
;;mediaimage9;mi.jpg;$siteResource/image/mi.jpg;image/jpg;hybris Accelerator;;mediaimage7
# Content Slots
INSERT_UPDATE ContentSlot;$contentCV[unique=true];uid[unique=true];cmsComponents(&componentRef)
#;;SiteLogoSlot;SiteLogoComponent
;;MiniCartSlot;MiniCart
;;SearchBoxSlot;SearchBox
;;SimpleBanner;SiteLogoComponent
#;;FooterContentSlot;bajajFooterComponent
;;RotatingImagesContentSlot;RotatingImagesComponent
;;BannerComponentContentSlot;BannerComponent3
# ContentSlotForPages
INSERT_UPDATE ContentSlotForPage;$contentCV[unique=true];uid[unique=true];position[unique=true];page(uid,$contentCV)[unique=true][default='homepage'];contentSlot(uid,$contentCV)[unique=true];;;
#;;SiteLogoContentSlotForPage;SiteLogoComponent;;SiteLogoSlot
;;MiniCartContentSlotForPage;MiniCart;;MiniCartSlot
;;SearchBoxContentSlotForPage;SearchBox;;SearchBoxSlot
;;SimpleBanner;SimpleBannerComponent;;SimpleBanner
#;;BajajContentSlotForPage2;BajajFooterComponent;;FooterContentSlot
;;RotatingImagesContentSlotForPage;RotatingImagesComponent;;RotatingImagesContentSlot
;;BannerComponentContentSlotForPage;BannerComponent;;BannerComponentContentSlot
Step 5:-
* Write cms-content.impex file needs import so goto HAC then click on Console and select ImpEx import and paste here click on import content.
Step 6:-
* Here we need to create required jsp files for Model Classes and also get position from ContentSlotForPage give that Position in landingLayout2Page.jsp (/****storefront/web/webroot/WEB-INF/views/responsive/pages/layout
/landingLayout2Page.jsp)
* jsp files like the following below
This is for company1.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div align="center">
<table border="1" cellpadding="1">
<caption>
<h2>Company&Employees relation</h2>
</caption>
<tr>
<th>employee Name</th>
<th>experience</th>
<th>Company Name</th>
<th>Company Location</th>
</tr>
<c:forEach var="emp" items="${employees1}">
<tr>
<td><c:out value="${emp.employeeName}" /></td>
<td><c:out value="${emp.experience}" /></td>
<td><c:out value="${emp.company1.companyName}" /></td>
<td><c:out value="${emp.company1.companyLocation}" /></td>
</tr>
</c:forEach>
</table>
</div>
|
employee1component.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:forEach var="i" items="${images}">
<img src="${i.url}">
</c:forEach>
<center>${paragraph.content}
<br><br>
Enum::${colors}
<br><br>
Map::<c:forEach items="${usercity}" var="c">
${c}<br>
</c:forEach>
<br>
Products List:: <br>
<c:forEach var="j" items="${productNames}">
${j}<br>
</c:forEach>
</center>
|
landingLayout2Page.jsp
<cms:pageSlot position="ElectronicComponent" var="feature" element="div">
<cms:component component="${feature}" element="div" class="no-space yComponentWrapper" />
</cms:pageSlot>
<cms:pageSlot position="Company1" var="feature" element="div" class="row no-margin">
<cms:component component="${feature}" element="div" class="col-xs-6 col-md-3 no-space yComponentWrapper" />
</cms:pageSlot>
|
Step 7:-
* Goto browser type URL like the following (https://bajaj.local:9002/bajajstorefront) then you will get like the following
Finally, we got this output
No comments:
Post a Comment