JSTL Functions Tag Library
This post is brought to you by Robert Brown, Senior WebSphere Commerce Consultant, www.redbaritone.com
WebSphere Commerce v6 uses the Java Server Tag Library (JSTL) language for most all starter store JSP code. The starter store JSPs typically include the four core tag libraries as indicated below at the top of each file
<%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<%@ taglib uri=”http://commerce.ibm.com/base” prefix=”wcbase” %>
<%@ taglib uri=”flow.tld” prefix=”flow” %>
Many times, it is handy to have a length function available. In prior versions of WebSphere Commerce, retrieving the length of an array or string variable was easy using Java Scriptlet code and length() or size() methods. In most cases, you can’t append length or size using the dot (.) operator without getting an EL exception. To get around this, first include the functions tag library below the other declarations at the top of the JSP.
<%@ taglib uri=”http://java.sun.com/jsp/jstl/functions” prefix=”fn” %>
Now, with the fn prefix, you can obtain the length of most any JSTL variable. As an example, the following code retrieves the length of a variable named JSTLVariableName.
${fn:length(JSTLVariableName)}
As a WC v6 example, a category JSP declares a CategoryDataBean and we define two variables to store the number of category attributes and the number of subcategories. Later in the JSP, we can control logic based on whether the attribute and subcategory count is greater than zero (0).
<wcbase:useBean id=”category” classname=”com.ibm.commerce.catalog.beans.CategoryDataBean” scope=”page” />
<c:set var=”cgryAttibuteCount” value=”${fn:length(category.categoryAttributes)}”/>
<c:set var=”cgrySubcategoryCount” value=”${fn:length(category.subCategories)}”/>
No WebSphere Commerce configuration changes are required to support the fn tag library functions. Length is just one of several supported EL functions introduced in the JSTL 1.1 specification which you can take advantage of that were not present in previous WC releases.
JSTL 1.1 (jsr-52 maintenance release) EL Functions:
* contains(string, substring) -> boolean
* containsIgnoreCase(string, substring) -> boolean
* endsWith(string, suffix) -> boolean
* escapeXml(string) -> String
* indexOf(string, substring) -> int
* join(collection, separator) -> String
* length(collection) -> int
* replace(inputString, beforeSubstring, afterSubstring) -> String
* split(string, separator) -> String[]
* startsWith(string, prefix) -> boolean
* substring(string, beginIndex, endIndex) -> String
* substringAfter(string, substring) -> String
* substringBefore(string, substring) -> String
* toLowerCase(string) -> String
* toUpperCase(string) -> String
* trim(string) -> String
Sunil said,
March 29, 2008 at 3:52 am
Hi,
I am getting a error like that
A error occured while evaluation fn:length
whats are the possible causes
Sunil