Translate

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