Because there is extensive linking between products and categories in the Pioneer Cycling store, we created a code fragment to produce hyperlinks to products or categories in ItemLink.jsp. This code fragment was created for convenience and to make our template pages easier to read.

<%
/* -------------------------------------------------------
 * Display a link to the Item (Product or Category).
 * The link will take you to the jsp page which displays
 * this Item.  The jsp page is fetched from the
 * "template.url" attribute on the Item.
 * If an Image is passed in, both the Image, and a text
 * link is displayed - clicking either the Image or the
 * text link brings the user to the above described jsp page.
 * ------------------------------------------------------- */
%>
<dsp:importbean bean="/atg/dynamo/droplet/IsNull"/>
<DECLAREPARAM NAME="Item"
   CLASS="java.lang.Object"
   DESCRIPTION="A Repository Item to display a link to - typically a
                Product or Category">
<DECLAREPARAM NAME="Image"
   CLASS="java.lang.String"
   DESCRIPTION="The optional param is used to display an image along with
                the link."
   OPTIONAL>
<DECLAREPARAM NAME="navAction"
   CLASS="java.lang.String"
   DESCRIPTION="How to change the navigation history. Choices are push,
                pop and jump.  Blank is treated as push."
   OPTIONAL>
<DECLAREPARAM NAME="DisplayText"
   CLASS="java.lang.String"
   DESCRIPTION="This optional string can be passed in to display different
                text (than what is default).  The default text to display
                is the Item's DisplayName"
   OPTIONAL>
<% /* Display link in bold: */ %>
<b>
<%
/* -------------------------------------------------------
 * Display a clickable link to the Item (Product or Category).
 * The link will take you to the jsp page which displays
 * this Item.  The jsp page to go to for this Item is
 * specified in the "template.url" attribute on the Item.
 * ------------------------------------------------------- */
%>

<dsp:getvalueof id="templateUrl" idtype="String" param="Item.template.url">
<dsp:a page="<%=templateUrl%>">
  <dsp:param name="id" param="Item.repositoryId"/>
  <dsp:param name="navCount"
             bean="/atg/commerce/catalog/CatalogNavHistory.navCount"/>

  <% /* These set for breadcrumb navigation: */ %>
  <dsp:param name="navAction" param="navAction"/>

  <dsp:getvalueof id="imageInp" param="Image">
  <core:ifNotNull value="<%=imageInp%>">
    <font color=000000>
      <dsp:getvalueof id="imageURL" param="Image.url"
           idtype="java.lang.String">
          <core:ifNotNull value="<%=imageURL%>">
            <img border="1" src="<%=imageURL%>">
          </core:ifNotNull>
      </dsp:getvalueof>
      </font>
      <br>
    </core:ifNotNull>
    </dsp:getvalueof>

  <%-- Show DisplayText if set, otherwise show item's display name --%>
  <dsp:valueof param="DisplayText"><dsp:valueof
       param="Item.displayName"/></dsp:valueof>

</dsp:a>
</dsp:getvalueof>

<% /* end link in bold: */ %>
</b>

The ItemLink.jsp code fragment takes at least one parameter: Item. The item must be a repository item (for example, a product or a category) that has a template.url value in the database. The value of the template.url property is the JSP template file that should be used to display this repository item. The code creates a hyper link to whatever JSP file is stored in the item’s template.url value.

<%/* Display a link to the Product: */%>
<dsp:include page="../common/ItemLink.jsp" flush="true">
  <dsp:param name="Item" param="Product"/>
  <dsp:param name="Image" param="Product.thumbnailImage"/>
  <dsp:param name="DisplayText" param="Product.displayName"/>
  <dsp:param name="navAction" value="jump"/>
</dsp:include>

The above call to the ItemLink.jsp code fragment is turned into the a HTML code similar to the following after it is rendered:

<b><a href="/PioneerCyclingJSP/en/catalog/product_generic.jsp?id=prod10023
&navAction=jump&navCount=5">
   <font color=000000>
     <img src="/MEDIA/ProductCatalog/m10027_helmets_red_sm.gif" border=1>
   </font>
   <br>
   Shatterproof Helmet
</a></b>
 
loading table of contents...