Samples >
Object snippets
WebSphere Commerce object snippets are reusable pieces of JSP code that represent display properties of business objects, such as an address, a price, or a catalog entry.
Among the chief benefits of using object snippets are the following:
- Smaller and more compact JSP pages
- Faster time to value achieved through reuse of object snippets on user-created store pages
- Single point of change for the object display, which ensures consistency across store pages
All of the WebSphere Commerce object snippets for the consumer direct sample storeand the B2B direct starter store are provided as JSPF files located in the following directory:
- WC_EAR/Stores.war/ storedir/Snippets/ReusableObjects
- workspace_dir\Stores\Web Content\ storedir\Snippets\ReusableObjects
Object snippets must be included into top-level JSP pages (also known as content panels) by means of static includes. Each object snippet expects certain variables to be declared on the including page. These variables are clearly identified in the snippet's introductory comment.
As an illustration of object snippet use, consider the common task of displaying an address on a store page. With the help of the address display object snippet, AddressDisplay.jspf, enabling the display of an address at a new location within a store can be accomplished in two easy steps:
- Declare a variable named address and assign it an AddressDataBean data bean, as instructed in the address display object snippet's introductory comment. For example:
<c:set var="address" value="${orderBean.orderItemDataBeans[0].currentAddressDataBean}" />
where orderBean.orderItemDataBeans[0].currentAddressDataBean is the AddressDataBean data bean that provides the shipping address associated with the first item in the order.
Include the address display object snippet by means of a static include such as the following:
<%@ include file="../ storedir/Snippets/ReusableObjects/AddressDisplay.jspf" %>
- JSP object snippet: AddressDisplay.jspf
This object snippet displays an address when included on a page, and the appropriate required parameters are set up.
- JSP object snippet: AddressEntryFormDisplay.jspf
This object snippet displays a set of address entry fields when included on a page, and the appropriate required parameters are set up.
- JSP object snippet: CatalogEntryPriceDisplay.jspf
This object snippet displays the price for a catalog entry.
- JSP object snippet: CatalogEntryThumbnailDisplay.jspf
This object snippet displays a catalog entry. By default all aspects of the catalogEntry are shown. Users may specify display parameters to limit what is shown (see optional parameters).
- JSP object snippet: NameEntryFormDisplay.jspf
This object snippet displays a set of name entry fields when included on a page, and the appropriate required parameters are set up.
Related concepts
Related reference
WebSphere Commerce JSP programming best practices
JSP object snippet: AddressDisplay.jspf
JSP object snippet: AddressEntryFormDisplay.jspf
JSP object snippet: CatalogEntryPriceDisplay.jspf
JSP object snippet: CatalogEntryThumbnailDisplay.jspf
JSP object snippet: NameEntryFormDisplay.jspf