Translate

Saturday, July 6, 2013

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
----------------------------------------------------


No comments: