Translate

Showing posts with label basic. Show all posts
Showing posts with label basic. Show all posts

Saturday, March 8, 2014

Example 6: Creating URLs for Hyperlinks


Creating URLs for hyperlinks:
Following instructions are for generating URLs for any asset type within FatWire/Oracle WebCenter Sites 11g.

GENERAL STEPS TO FOLLOW:
  • Add render taglib to your JSP.
  • Generally, you need to know few parameters like asset type(c), asset id(cid), parent id(p), packedargs(packedargs), arguments to pass (render:argument)
  • Use render:getpageurl, render:getbloburl, render:gettemplateurl and render:gettemplateurlparameters according to your requirement and generate the output variable.
  • Use string:stream to render the output variable wherever required. (Don't forget to add String taglib to your JSP)
CASE 1: render:getpageurl : This tag creates URLs for assets that are not blobs. NOTE: if you are creating links to assets that are being rendered through templates, you should use the render:gettemplateurl tag instead. This tag creates a URL for an asset, processing the arguments passed to it from the calling element into a URL-encoded string and returning it in a variable.

<render:getpageurl pagename="SiteCatalogPageEntry"
       cid='<%=ics.GetVar("cid")%>'
       c="AssetType"
       wrapperpage="WrapperPage"
       outstr="theURL"/>

CASE 2: render:bloburl : Creates a BlobServer URL without embedding it in an HTML tag and thus, provides an output variable which can be used inside img tag or other.

<render:getbloburl
       blobtable="ImageFile"
       blobcol="urlpicture"
       blobheader='<%=ics.GetVar("asset:mimetype")%>'
       blobkey="id"
       blobwhere='<%=ics.GetVar("asset:id")%>'
       outstr="theURL"/>
<img src='<%=ics.GetVar("theURL")'/>

CASE 3: render:gettemplateurl : Generates a valid URL to an asset, rendered through a template, with optional wrapper page support. User-defined arguments will be packed if wrapperpage is specified. This tag is the preferred method for generating a URL to an asset (provided that the asset is being rendered through a Template, which is the recommendation). It effectively replaces render:getpageurl in most (but certainly not all) cases. Instances of this tag must contain information about who the caller is in order to operate correctly. The caller must be either another Template or a CSElement. This tag will not operate correctly without valid information about the caller i.e. need to provide tid and ttype parameters.

<render:gettemplateurl
       outstr="aUrl"
       c='AssetType'
       cid='AssetId'
       tname='TemplateName (mostly it is layout)'
       wrapperpage='Wrapper' >
</render:gettemplateurl>

CASE 4: render:gettemplateurlparameters : This tag does not create any url but looks up all of the URL parameters that would have been set into a URL and returns them in the form of a List so that can be passed as used as required. Basically used in Satellite:form as below.

<%-- Look up the parameters --%>
<render:gettemplateurlparameters
       outlist="args"
       args="c,cid"
       tname='<%=ics.GetVar("LayoutVar")%>'
       wrapperpage='<%=ics.GetVar("WrapperVar")%>'>
   <render:argument name="p" value='<%=ics.GetVar("p")%>'/>
</render:gettemplateurlparameters>
<satellite:form method="post" id="AddToCartForm">
   <%-- Loop through all of the url parameters and set them
        into the form as hidden fields so the data is sent
        back to Sites as needed.  These variables will include
        pagename, wrapperpage, c, cid, p, possibly rendermode
        and possibly others. --%>
   <ics:listloop listname="args">
       <input type="hidden"
              name="<string:stream list="args" column="name"/>"
              value="<string:stream list="args" column="value"/>" />
   </ics:listloop>
</satellite:form>

CASE 4: satellite:link : This tag generates URL to a page (pagename in SiteCatalog entry) which is present in the OracleWCS/FatWire.

<satellite:link pagename="PAGENAME" outstr="theURL">
 <satellite:parameter name="param_name" value="param_value"/>
</satellite:link>

INFO:
  • Most of time, render:gettemplateurl is used to generate urls for assets
  • While creating URLs in Template or CSElement, developer should keep in mind to include all the parameters by passing them via arguments (render:arguments) so that no errors are found from assembler when it tries to create vanity urls.
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------


Sunday, December 8, 2013

Example 5: Searching Assets

Searching assets is very basic functionality required in various online sites whether be a content search, tagged-content search or even media asset search. Content (Assets) can be any assets like product assets, article assets, etc.

Following instructions are for searching FLEX assets using searchstate tags.

GENERAL STEPS TO FOLLOW:
  1. For using searchstate tag, add the searchstate taglib at starting of your JSP/XML. 
  2. Create an empty searchstate object (using searchstate:create tag), which can contain 2 operations: "and" & "or".
  3. Add constraint to the searchstate i.e. adding a condition for restricting search based on single attribute or another searchstate (also called as nested constraint). For adding constraint, use anyone of the following tag as required: searchstate:addlikeconstraint, searchstate:addnestedconstraint, searchstate:addrangeconstraint, searchstate:addsimpleconstraint, searchstate:addsimplestandardconstraint, searchstate:addstandardconstraint, etc. according to you requirement. 
  4. Set the searchstate (Using assetset:setsearchedassets tag)
  5. Get the required attribute values (Using assetset:getmultiplevalues or assetset:getattributevalues)
  6. Then list through the result (Using ics:listloop and ics:listget tag)
CASE 1: A simple case: Finding attributes of a flex asset to search against value of one attribute

<searchstate:create name="ss" />
<searchstate:addsimplelikeconstraint name="ss" attribute="cat2" value="Watt%"/>
<assetset:setsearchedassets name="as" constraint="ss" assettypes="Products"/>
<assetset:getattributevalues name="as" attribute="productdesc" listvarname="resultlist"/>
<ics:listloop listname="resultlist">
<ics:listget listname="resultlist" fieldname="value"/><br/>
</ics:listloop>


Apart from using searchstate tags, there are other tags which can be used for searching assets (flex or basic or table data) which are described briefly below:
  1. ics:sql - It executes inline SQL statement. You can write a SQL query and search against tablename which should be registered SYTEMINFO table.
  2. ics:callsql - It retrieves and executes a SQL query stored in the SYSTEMSQL table
  3. ics:sqlexp - This tag is used only to build where clause based on given set of parameters. It does not execute any statement. It passes a column name and an expression that contains the column name to be used as the left side in the where clause.
  4. ics:selectto - It executes a simple query from a table, which is equivalent to run a simple SQL query like select * from tablename
  5. asset:search - It locates a list of asset primary table rows based on the asset type and a set of search criteria. Criteria can be defined which can narrow your search. Not recommended for searching FLEX assets.
  6. asset:list - This tag queries the database and retrieve a list of assets that meets the specified criteria. It creates a list of assets of one type. Specific criteria could be against field/value of certain tablename, passing argument in field name/value pairs, etc. to restrict the list.
Detailed explanation is provided in Tag Reference/Developer guide.

INFO:
  • The above case is very simple case provided by tag reference itself.
  • Check the examples and details of every searchstate tag in TagReference and Developer Guide
  • Following is the list which shows which searchstate tags to use for what case:
    • searchstate:addsimplestandardconstraint - Adds an attribute name/single value constraint to an existing searchstate object.
    • searchstate:addlikeconstraint - Adds a list of attribute like name/value constraints into a new or existing searchstate object.
    • searchstate:addnestedconstraint - Nests a searchstate as a constraint within another searchstate.
    • searchstate:addrangeconstraint - Adds a range constraint to a searchstate on a specific attribute.
    • searchstate:addsimplelikeconstraint - Adds an attribute like name/value constraint into a new or existing searchstate object.
    • searchstate:addstandardconstraint - Adds a list of attribute name/value constraints into a new or existing searchstate object.

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


Saturday, November 16, 2013

Example 4: Rendering Blobs

This post illustrates how to render blobs (BINARY LARGE OBJECTS)

GENERAL STEPS TO FOLLOW:
  1. Load the flex asset (using assetset tags) 
  2. Get the value of imagefile attribute in list (using assetset:getattributevalues tag) 
  3. Retrieve information using blobservice tags 
CASE 1: If we are using normal upload functionality for images while creating asset and if you know asset type(c) and asset id (cid). This is used to render image asset as shown below:

<ics:if condition='<%=ics.GetVar("c")!=null && ics.GetVar("cid")!=null%>'><ics:then>
<!-- Use assetset tags to load FLEX ASSETS. CheckOut tagReference for further details. -->
<assetset:setasset name='Media' type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues name='Media' immediateonly='true' typename='FlexAssetAttributeType' attribute='ImageFile' listvarname='mediaImageList' />
                 
<!-- 
BLOB attributes are to be rendered differently and uses BlobServer servlet.
Don't forget to include tld in your template/CSElement for BlobService -> taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld"
 -->                  
<ics:if condition='<%=ics.GetList("mediaImageList")!=null && ics.GetList("mediaImageList").hasData()%>'>
<ics:then>        
      <ics:listloop listname='mediaImageList'>
<ics:listget listname='mediaImageList' fieldname='value' output='media_image' />
      
 <blobservice:gettablename varname="uTabname"/>
 <blobservice:getidcolumn varname="idColumn"/>
 <blobservice:geturlcolumn varname="uColumn"/>
 
 <render:getbloburl 
 blobtable='<%=ics.GetVar("uTabname")%>' 
 blobcol='<%=ics.GetVar("uColumn")%>'
 blobheader="image/jpeg"
 blobkey='<%=ics.GetVar("idColumn")%>'
 blobwhere='<%=ics.GetVar("media_image")%>' 
 outstr="imageURL"/> 
    </ics:listloop>
   
<img  src='<%=ics.GetVar("imageURL")%>' >
  
      </ics:then></ics:if>   
          
</ics:then></ics:if>

INFO:
  • Media is just a name used in Assetset tag
  • This code in template should be created once and called from various template/cselement as required by passing c and cid to render blobs.
  •  FlexAssetAttributeType is attribute type (For eg: It would be something like Media_A if you have created flex family using Media_* where *=CD, C, PD, P, A and F)
  • Always do a null check and use log messages to capture errors.

CASE 2: This case may be trickier. If you have stored your images under some folder say "image" in Shared directory, then you can obtain url value of blob, we can use blobservice.readdata as followed and render the image:

<ics:if condition='<%=ics.GetVar("c")!=null && ics.GetVar("cid")!=null%>'><ics:then>
<!-- Use assetset tags to load FLEX ASSETS. CheckOut tagReference for further details. -->
<assetset:setasset name='Media' type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid")%>' />
<assetset:getattributevalues name='Media' immediateonly='true' typename='FlexAssetAttributeType' attribute='ImageFile' listvarname='mediaList' />
<%if (ics.GetList("mediaList") != null && ics.GetList("mediaList").hasData()) { %>
<ics:listget listname='mediaList' fieldname='value' output='mediaFile' />
<%} %>
<%if (ics.GetVar("mediaFile") != null ) { %>
<blobservice:readdata id='<%=ics.GetVar("mediaFile") %>' listvarname="mediaInfo"/>
<%} %>
<% if (ics.GetList("mediaInfo") != null && ics.GetList("mediaInfo").hasData()) 
{
ics.SetVar("mediaURL", "/media/" + ics.GetList("mediaInfo").getValue("urldata").replace("\\", "/"));
}
%>

<img src='<%= ics.GetVar("mediaURL") %>' >

INFO:
  • Create one folder "media" in Shared directory and place all your images.
  • Add this property in server.xml if you are using apache tomcat which is located in conf directory:     <Context path="/media" docBase="<installed location of fatwire>/Shared/ccurl" reloadable="true" debug="1" crossContext="true"/>
----------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
----------------------------------------------------

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


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