Defining references to static content in an MVCPortlet JSP file

According to Portal's portlet programming best practices, all static content asset files, such as images and static HTML, should be included into the portlet application for ease of installation and deployment. However, the MVCPortlet also allows external references to these static contents using a URL defined in the URL provider, with a default JNDI name url/com/ibm/commerce/foundation/client/portal/ExternalContent. However, this JNDI name can be overriden by defining a portlet preference, .ExternalContentURLReference.

A JSP tag, <wcp:encodeURL>, is provided to automatically set the URL prefix of the given static content. This tag uses the WebSphere Commerce store static content store directory as the location prefix of the portlet static content. The information is retrieved through a service call to the Infrastructure component. Optionally, it is possible to override this static content location prefix by defining a portlet preference called .ExternalContentURLReference. The value of this preference is a JNDI name, such as url/com/ibm/commerce/foundation/client/portal/ExternalContent, defined through the URL provider service. This tag takes in two optional attributes as well:

remote
States whether to use the URL prefix from the URL provider. The default is true.
escapeStore
States whether to exclude the store directory prefix. The default is false.

There are three possible use case scenarios for store related static content:

  1. On the WebSphere Portal web server. For example: <wcp:encodeURL url="images/catalog/something.jsp" /> with external URL reference set to http://portal_server_web_server/alias
  2. Within the MVCPortlet WAR. For example: <wcp:encodeURL url="images/catalog/something.jsp" remote="false" />
  3. Remotely on a WebSphere Commerce web server. For example: <wcp:encodeURL url="images/catalog/something.jsp" /> with external URL reference set to http://hostname/wcsstore

With the additional escapeStore attribute, it is possible to include references to static content which can be used generically across all stores. Setting the escapeStore attribute to "true" will make the tag exclude the store directory in the resulting URL.

The final URL to the static content will be composed of 3 parts:

<protocol + hostname + port + context root or web alias> / <store directory> / <static content relative path>

An example of a non-store specific local static content reference is:


<wcp:encodeURL url="images/something.gif" remote="false" escapeStore="true" />

and this will produce an output of:


/wps/wcportlet/jsp/html/images/something.gif

Note: this URL will be encoded by WebSphere Portal Server.

An example of a store specific remote static content reference is:


<wcp:encodeURL url="images/catalog/something.gif" />

and this will produce an output of:


http://hostname/wcsstore/ConsumerDirect/images/catalog/something.jpg

where the URL provider says http://hostname/wcsstore and ConsumerDirect is the store directory used for the current storeId in the business content.