Thursday, November 28, 2013

Rendering a BLOB Attribute in a Template

There are at least two ways for rendering a BLOB attribute. First, and used quite a lot, implies using WebCenter Sites Asset API and scriptlets added in the JSP page. Second method uses a couple of JSP tags and provides a more elegant solution to the problem of rendering BLOB attributes.

In the following example I am using an asset of type DMedia_C with a blob attribute named "file".


Example:


<%--Load the current image (media) asset --%>
<assetset:setasset name="currentImage" type='<%=ics.GetVar("c") %>' id='<%=ics.GetVar("cid") %>'/>

<%--Get the file attribute - the blob that we want to display  --%>
<assetset:getattributevalues name="currentImage" listvarname="fileList" attribute="file" typename="DContent_A"/>

<blobservice:gettablename varname="blobTable"/>
<blobservice:getidcolumn varname="idColumn"/>
<blobservice:geturlcolumn varname="dataColumn"/>

<render:getbloburl outstr="imageUrl"
blobtable='<%=ics.GetVar("blobTable") %>'
blobcol='<%=ics.GetVar("dataColumn") %>'
blobkey='<%=ics.GetVar("idColumn") %>'
blobwhere='<%=ics.GetList("fileList").getValue("value") %>'/>


<img src='<render:stream variable="imageUrl"/>'/>


Don't forget to add the used tags definition to the page:

<%@ taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld" %>

No comments: