It is highly recommended to use JSTL to build JSP Pages in WCS: ${...} --Expression Language
- Naming Convention of methods in Bean for boolean check
boolean itemsReturned=false;
public boolean isItemsReturned() {
return itemsReturned;
}
<if test="${!orderStatus. itemsReturned }">
</c:if>
- Setting Variables in a JSP:
- <c:set var="status" value="P"/>
- <c:set var="errorZipCounter" value="0" />
- <c:set var="accDisplaycount" value="${accDisplaycount + 1 }" />
- If, Else this is the equivalent of If Else as JSTL does not have the usual If Else
<c:choose><c:when test="${!empty WCParam.source}"><c:set var="source" value="${WCParam.source}" /></c:when><c:otherwise><c:set var="source" value="${source}" /></c:otherwise></c:choose>
- For statement: counter is current status variable, you could get index\first\last\current\count status.
<c:forEach items="${orderList}" var="order" varStatus="counter">If the orderList is a list of orderdatabeans or something, you could loop through them</c:forEach>
- If statment example:
<c:if test="${(!empty WCParam.orderStatus && (WCParam.orderStatus eq 'Y'))}">You can use eq,ne,lt,gt,ge,le other relational operators</c:if>
- Constructing hyperlinks: Prep-ends the name of current servlet context,URl encoding of request params and values, URl re-writing for session management.
<a href="<c:url value='/content/sitemap.jsp'/>">View sitemap</a><c:url var="productDisplayURL" value="ProductDisplay"><c:param name="catalogId" value="${WCParam.catalogId}"/><c:param name="storeId" value="${WCParam.storeId}"/><c:param name="langId" value="${WCParam.langId}"/><c:param name="productId" value="${accessoryItem.itemId}"/></c:url>
- Include content of a JSP into another JSP:
<c:import url="../../CurrentOrderSection/OrderItemDetailsDisplay.jsp"><c:param name="orderId" value="${WCParam.orderId}"/></c:import><% out.flush(); %><c:import url="${storeDir}include/footer.jsp"/><% out.flush(); %><% out.flush(); %><c:import url="{storeDir}include/header.jsp"/><% out.flush(); %>
- Removes a variable from scope:
<c:remove var="wishListURL" scope="page"/>
- Print the value: Also helpful to print values in JavaScript. The <c:out> tag evaluates an expression and outputs the result on the page
status:<c:out value="${WCParam.status}"/>firstName:<c:out value="${orderDetailsVB.orderBillingAddress.firstName}"<script language="javascript" src="<c:out value="${storeJavascriptDir}/browser_detect.js" />"></script>
- Using functions: There are several functions that are very helpful
var paramvalues = "<c:out value="${fn:substring(config.params, 1, -1)}" escapeXml="false"/>";<c:set var="dispalyPrice" value="${fn:substringAfter(orderItemTotalPrice,)}"/><c:when test="${fn:indexOf(locale, 'en') >= 0}"></c:when>
- useBean to instantiate and auto populate the bean
<wcbase:useBean id="orderDetailsVB" classname="com.abc.order.beans.OrderDetailsViewBean"><c:set target="${orderDetailsVB}" property="orderId" value="${WCParam.orderId}"/><c:set target="${orderDetailsVB}" property="orderStatus" value="${status}"/></wcbase:useBean><wcbase:useBean id="productVB" classname="com.abc.catalog.beans.ItemViewBean" scope="request" ><c:set target="${productVB}" property="itemId" value="${WCParam.catentryId}" /></wcbase:useBean>

