JSP programming best practice: Use the Commerce-specific tag for bean activation
WebSphere
Commerce data beans require activation prior to their use. WebSphere
Commerce provides a Commerce-specific version of the useBean tag,
<wcbase:useBean>,
that performs data bean activation in Java-free manner and is the
recommended method of data bean activation in store JSP pages.
<
jsp:useBean
id="categoryBean"
class="com.ibm.commerce.catalog.beans.CategoryDataBean">
<%
com.ibm.commerce.beans.DataBeanManager.activate(categoryBean,
request, response); %>
</jsp:useBean>
<
wcbase:useBean
id="categoryBean"
Note:
Data bean activation can fail and cause an exceptional condition.
To comply with the JavaServer Pages Specification requirement that
no output be written to the output stream when forwarding to other
Web assets, including error pages, data beans should be activated
at the beginning of the JSP page.
WebSphere Commerce useBean tag
The useBean tag instantiates a
WebSphere Commerce data bean and automatically populates it for you.
A new programming direction has also been undertaken with our
starter stores that now use the JavaServer Pages Standard Tag
Library (JSTL) to perform view logic, instead of Java code. At the
same time, business logic has been moving into data beans. The
combination of these steps allows for less Java code in a JSP page.
The useBean tag takes the following
attributes:
In order to be able to use the new
useBean tag library, a JSP page must first be told how to locate the
tag. In order to locate and use the new tag, the following line must
be located at the top of the JSP file:
This line will make the useBean tag available to the JSP page with the prefix of wcbase.<%@ taglib uri="http://commerce.ibm.com/base" prefix="wcbase"
%>
The following are examples of using the useBean tag:
<wcbase:useBean
id="orderBean"classname="com.ibm.commerce.order.beans.OrderDataBean"scope="page"/>
-
A new OrderDataBean is created and is accessible on the JSP page as
orderBean. In this case, the useBean tag has a body. Inside of the
bean's body tag, the <c:set> is
used to set properties on the OrderDataBean.
<wcbase:useBean id="orderBean"
classname="com.ibm.commerce.order.beans.OrderDataBean"
scope="page">
<c:set value="${orderId[0]}" target="${orderBean}"
property="orderId"/>
</wcbase:useBean>
<wcbase:useBean
classname="com.ibm.commerce.fulfillment.beans.InventoryDataBean"
id="SivaInventory"
>
<c:set
property="dataBeanKeyCatalogEntryId"
target="${SivaInventory}"
value="10002"
/>
<c:set
property="dataBeanKeyFulfillmentCenterId"
target="${SivaInventory}"
value="10001"
/>
<c:set
property="dataBeanKeyStoreId"
target="${SivaInventory}"
value="10001"
/>
</wcbase:useBean>
<c:out
value="${SivaInventory.quantity}"
/>
<!--
<wcbase:useBean
classname="com.ibm.commerce.catalog.beans.AttributeDataBean"
id="attrib">
<c:set
property="dataBeanKeyAttributeId" target="${attrib}"
value="10004"></c:set>
</wcbase:useBean>
<c:out
value="${attrib.name}"/> -->
Hello Team,
ReplyDeletecan you please let me know if I can use the below "catch" tag in the following
case:"no output be written to the output stream when forwarding to other Web assets, including error pages"
This comment has been removed by the author.
ReplyDeleteHi,
ReplyDeleteI want to know whether we can populate OrderDataBean other than orderId.