Wednesday, August 3, 2011

JSTL | Top 10 JSTL statements most often used !!!

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>

2 comments:

  1. hi,
    Your post is very nice.I have some doubts in creating pattern files
    For the products and category ,i used default pattern names which available in wcs.But For series landing page ,I create new jsp page view name is AttachPageView.
    And I create a new pattern file named as SEOURLPatterns-ext.xml,But I am getting error as Invalid xml file.Please help me on this issue.

    Below I mention the steps what i followed ,
    Step 1:create a new pattern file.named as SEOURLPatterns-ext.xml




    /StoreToken:CatalogToken/LanguageToken/CategoryToken/ProductToken/SeriesTermToken

















    Series




    -->

    Step 2:Put entry for SeriesTermToken in setokenusgtype table ,entered TOKENUSGTYPE as series and PRIMARYTOKEN as SeriesTermToken

    Step 3: Put entery in seourl table, TOKENNAME as SeriesTermToken,TOKENVALUE as SeriesTermToken.

    step 4:Also put entry in seourlkeyword table, URLKEYWORD as series.

    step 5:Used pattern name in jsp page








    step 6:Restart the server.
    step 7:Expected seo url:webapp/wcs/store/servlet/en/us/laptops/dell/series
    Laptops:keyword for category token,dell:keyword for producttoken(These two are already in the seourlkeyword tables,also used for other

    patterns also)
    I could not get the above url for that Series landing page it throws geniric error and error comes on invalid xml.

    Note:for the pdp page I am using exisiting patterns and I am getting the url webapp/wcs/store/servlet/en/us/laptops/dell/

    Please help me on this issue And Reply to nithiphils@gmail.com


    Posted to :http://wcs-dharmendra.blogspot.com/2013/05/wcs-websphere-commerce-server-seo.html


    ReplyDelete
  2. Excellent Article on Frequently used JSTL. I think DataSource is also used frequently

    Java EE online training | Java Training Institutes in Chennai

    ReplyDelete