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:
- id
- Required: The ID that the new bean will have. This ID must be a valid Java identifier and must be unique as it is also used to create a new scripting variable for the JSP page. The ID must also be unique to a page.
- classname
- Required: The class for the data bean that will be instantiated.
- scope
- The scope in which the bean should be stored such as page, request, session, and application. The default scope is page.
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:
<%@ taglib uri="http://commerce.ibm.com/base" prefix="wcbase" %>
This line will make the useBean tag available to the JSP page with the prefix of wcbase.
The following are examples of using the useBean tag:
- A new OrderDataBean is created and is accessible on the JSP page as orderBean.
<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>
Related concepts
Display design pattern
WebSphere Commerce framework overview
Related tasks
Use resource bundles in store pages
Related reference
JSP programming best practice: Use the Commerce-specific tag for bean activation