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


2 comments:

Anonymous said...

can you please explain the concept of named associations and unnamed association?

Guddu said...

Named and Unnamed associations make more sense if you are using old product - FatWire as Page assets used to be more kind of Basic assets. Basic assets have association with other assets of same or different asset types using "Named" and "Unnamed" association. For more details, check the official guide - http://docs.oracle.com/cd/E28662_01/doc.76/content_server/cs_developer_76p2.pdf

In WebCenter Sites (any version 11g or 12c), I don't see a case of Unnamed association. But there may be a case of using "Named" association. For e.g. if you want to create an association of type - Asset but with different multiple asset types, then you would go "named" association. If you want to create an asset association of specific asset type, then create an attribute to type asset with selection of assettype.

I hope this clears your question.