Ninja-Script — When all else fails

Posted by Phil on February 15, 2008 under Websphere Commerce | Be the First to Comment

When all else fails, what do you do? You call a ninja, and when he shows up he gives you a piece of code, or knowledge. Now this knowledge came in the form of a scriptlet which I know we frown upon, but here it is, because it runs back and finds the parent category, and if it is there then we use the logic to place a change in the sidenav of NordicTrack.


<%@ include file="CatalogUtilities.jspf" %>

<%
try {

Integer storeIdInt = Integer.valueOf((String)pageContext.getAttribute("storeId"));
Long catalogId = Long.valueOf((String)pageContext.getAttribute("catalogId"));
java.util.LinkedList list = null;
String categoryId = (String)pageContext.getAttribute("categoryId");
if(categoryId != null && !categoryId.equals("")){
list = (java.util.LinkedList)getCatGrpHierarchyByCatalogIdAndCatGrpId(request, response, storeIdInt, catalogId, categoryId);
} else {
Long catEntryId = Long.valueOf((String)pageContext.getAttribute("productId"));
list = (java.util.LinkedList)getCatGrpHierarchyByCatalogIdAndCatEntryId(request, response, storeIdInt, catalogId, catEntryId);
}
pageContext.setAttribute("rootCategory", list.getFirst());
} catch (Exception e) {
e.printStackTrace();
}
%>

What this all did for us was allow us to see the actual root parent of the catalog.  So by finding that out we can then be as deep into the catalog as we want and still be able to write code that modifies something on the page based on if you are even in that category.  What we ended up doing was checking the root parent to find out if the CachedSideBar.jsp needed to be modified when displayed to customers.  It’s all checked into CVS, so pull it down and take a look if you’d like.