Tuesday, April 7, 2015

Frequent JSTL use in IBM WCS

1.     Control statement :
 <if test="${!orderStatus. itemsReturned }">
                  </c:if>
2.      Setting Variables in a JSP:
 <c:set var="status" value="P"/>
 <c:set var="errorZipCounter" value="0" />
 <c:set var="accDisplaycount" value="${accDisplaycount + 1 }" />


3.  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>


4. 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>
5. 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>
6.  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>
7.  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(); %>
8. Removes a variable from scope:
                 <c:remove var="wishListURL" scope="page"/>
9. 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>
10. 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>
11. useBean to instantiate and auto populate the bean

 <wcbase:useBean id="productVB" classname="com.abc.catalog.beans.ItemViewBean"  scope="request" >    
   <c:set target="${productVB}" property="itemId" value="${WCParam.catentryId}" />    

</wcbase:useBean>  

No comments:

Post a Comment