Translate

Saturday, July 6, 2013

Example 3: Rendering Associations

This example illustrates how to render ASSOCIATIONS - Named and Unnamed (Collections, Query and Asset associated)

GENERAL STEPS TO FOLLOW:
  1. Load the asset (using asset:load tag)
  2. Get the association (using asset:children tag)
  3. Fetch attributes (by looping through list using ics:listloop tag)
CASE 1: Retrieving named association (Consider a case where a query asset is associated with Page).

<asset:load name="HomePage" type="Page" field="name" value="Home" site='<%=ics.GetVar("site")%>'/>
<asset:children name="HomePage" list="LatestNewQuery" objectype="Query" code="LatestNews"/>
<ics:listloop listname="LatestNewQuery"> 
     <ics:listget listname="LatestNewQuery" fieldname="description"/>
</ics:listloop>

INFO:
  • The above code retrieves the query asset that has been associated with a page asset through the "LatestNews" association.
  • code="LatestNews" - This is required to retrieve NAMED association.
  • If asset is associated to another asset, use the above way. (for eg: list of images associated with article assets.)
CASE 2: Retrieving unnamed association (Collection asset consisting of asset type - Article):


<asset:load name="NewsCollection" type="Collection" objectid='<%=ics.GetVar("id")%>'/>
<asset:get name="NewsCollection" field="name"/><br/>
<asset:children name="NewsCollection" code="-" order="nrank" objecttype="Article" list="articleList"/>
<ics:listloop listname="articleList">
     <ics:listget listname="articleList" fieldname="description"/><br/>
</ics:listloop>

INFO:
  • The above code retrieves a collection of articles and then displays the description field of each article
  • Notice: for unnamed associations, we use "-" in code parameter (code="-") while using asset:children tag.
  • order="nrank" - This can be used to retrieve list sorted by rank started at number 1. Use "nrank desc" for descending order.
  • Above mentioned example assumes that your asset was loaded for further purpose to load siteplan or to scatter other values using asset:scatter. But if you only want to retrieve associated assets, don't use asset:load. You can directly load association by providing assetid and asset type info to <asset:children> tag (Check how in tag reference)

--------------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
--------------------------------------------------------


All Tutorial Links

-------------
INDEX
-------------

List of topics covered in this blog. You may also like my other blogs.

Development/Coding using TAGS

Development/Coding using ASSET API (CRUD Operation on Asset)
Tips and Tricks
  • FatWire/WebCenter Sites debugging techniques
  • Optimize usage of Admin and Advanced UI
  • Important list of SQL queries
  • WebCenter Sites tools
  • Using Groovy elements in WCS

Check out my other blogs(Requires invite):
Customizations: Oracle WebCenter Sites / FatWire customizations
Sample codes: Random code snippets
Oracle WebCenter Sites 12c: New OWCS 12c

---------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
---------------------------------

Example 2: Rendering Flex Asset

This example illustrates how to render FLEX ASSET in different situations. Although there are many examples available in developer guide, here I am providing general steps and some scenarios.

GENERAL STEPS TO FOLLOW:
  1. Use assetset:setasset tag to load the flex asset (obviously we should know asset type(c) and asset id(cid)).
  2. Use assetset:getmultiplevalues or assetset:getattributevalues to retrieve information after the flex asset is loaded.
  3. Fetch attributes (looping through list using ics:listloop tag) In the following cases it is assumed that we know asset id and asset type. (Searchstates to retrieve flex assets would be discussed in different tutorial)
CASE 1: Retrieving flex attributes using assetset:getmultiplevalues tag (for eg: retrieving price and article name of an article asset.)

<assetset:setasset name="myassetset" type='<%=ics.GetVar("c")%>' id='<%=ics.GetVar("cid")%>' />
<assetset:getmultiplevalues name="myassetset" prefix="ArticleList" immediateonly="false"> <assetset:sortlistentry attributetypename="Article_A" attributename="Price" direction="ascending"/>
<assetset:sortlistentry attributetypename="Article_A" attributename="ArticleName"/>
<assetset:getmultiplevalues/>

<!-- Display results -->
Article Price List: <br/>
<ics:listloop listname="ArticleList:Price">
     <ics:listget listname="ArticleList:Price" fieldname="value" /><br/>
</ics:listloop>
Article Name List:<br/>
<ics:listloop listname="ArticleList:ArticleName">
     <ics:listget listname="ArticleList:ArticleName" fieldname="value" /><br/>
</ics:listloop>


INFO:
  • Using assetset:setasset tag is basic step to do for loading the flex asset.
  • Use assetset:getmultiplevalues to retrieve all the attributes at once, its like fetching all the results in one go. But there are limitations on this tag that it can not be used to retrieve attribute of type - "text", you have to use assetset:getattributevalues tag described below in case 2.
  • immediateonly - using this can be useful in some scenarios like if you want the value of attribute of the parent asset. For eg: Suppose I have hierarchy like Cricket is my parent asset(which contains "parentname" as one attribute) and ODI is child asset(which contains some attributes.). If I want the value of the attribute - "parentname", i don't need to load the parent asset i.e. Cricket in our case, to get the "parentname" attribute value as it is inherited in child assets too. So to get the parent attributes we set immediateonly="false" in assetset:getattributevalues tag.
  • direction - ascending or descending - Sorts assets. This scenarios is helpful when you have list of flex assets and then looping through that list and then trying to fetch the attributes which you require and want to sort them by a particular attribute.
  • This tag is used when you want all the attributes of flex assets in one go except the attribute of type - "text"CASE 2: Retrieving flex attributes using assetset:getattributevalues
CASE 2: Retrieving flex attributes using assetset:getattributevalues tag (for eg: retrieving price and article name of an article asset.)

<assetset:setasset name="myassetset" type='<%=ics.GetVar("c")%>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues ordering="descending" name="myassetset" typename="Article_A" attribute="Price" immediateonly="true" listvarname="pricelist"/>
<assetset:getattributevalues name="myassetset" typename="Article_A" attribute="ArticleName" listvarname="articlenamelist"/>

<!-- Display results -->
Article Price List: <br/>
<ics:listloop listname="pricelist">
     <ics:listget listname="pricelist" fieldname="value" /><br/>
</ics:listloop>
Article Name List:<br/>
<ics:listloop listname="articlenamelist">
     <ics:listget listname="articlenamelist" fieldname="value" /><br/>
</ics:listloop>


INFO:
  • This tag generates one or more database queries, in order to retrieve the value of the attributes specified
  • Similar to case 1, we can get parent attributes too and can have ordering too.
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------


Example 1: Rendering Basic Asset

This example illustrates how to render BASIC ASSET in different situations.

GENERAL STEPS TO FOLLOW:
  1. Load the basic asset (using asset:load tag) 
  2. Scatter the loaded basic asset (using asset:scatter tag) 
  3. Retrieve information after scattering the asset via prefix:attributename (using ics:getvar tag) 
CASE 1: If you know asset type(c) and asset id (cid). This is basically used to retrieve information from the basic asset usually to render on page. Following example shows retrieving name after the basic asset is loaded and scattered.

<asset:load name="anyName" type='<%=ics.GetVar("c")%>%>' objectid='<%=ics.GetVar("cid")%>' flushonvoid="true" />
<asset:scatter name="anyName" prefix="anyPrefixName" /> 

<ics:getvar name="anyPrefixName:name"/>

CASE 2: If you know asset type, a field, value and site. This is generally used to get association using asset:children tag after the asset is loaded.

<asset:load name="anyName" type="assetTypeName" field="name" value="someAssetName" site='<%=ics.GetVar("site")%>'/>
(Use asset:children to get associations... COVERED IN LATER EXAMPLES) <asset:get name="anyName" field="description" /> <ics:getvar name="description"/>


INFO:
  • flushonvoid ensures that pages cache for the page is flushed if asset is not loaded or asset is deleted. 
  • Don't use this tag to render flex assets, its very costly (in terms of retrieving info from db as flex asset stores data in various tables whereas basic asset stores info in one table) 
  • Never hardcore asset id (cid) as this asset id keeps on changing from one environment to other. Also try to avoid hardcoding asset type (try to use render:lookup tag) 
  • After the asset is loaded, use asset:scatter tag if you want all the attributes in one go or if only 1 or 2 attributes are required, then use asset:get tag. 
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------