Problem comparing Strings in JSTL

Hi,

I have the following code and basically need to determine whether or not the path attribute for the var 'cib_navLink' starts with the String Object (extranetUrl) from the scriplet code.

<%

Preferences prefs = (Preferences) pageContext.getAttribute(PageHelper.PREFS_ATT_NAME,PageContext.APPLICATION_SCOPE);

IItem item = (IItem) pageContext.getAttribute("requestItem");

HashMap sitePrefs = prefs.getSitePreferences(item);

String extranetUrl ="";

try

{

extranetUrl = (String) sitePrefs.get("extraneturl");

pageContext.setAttribute("extraneturl", extranetUrl, PageContext.REQUEST_SCOPE);

}

catch (Exception e)

{

System.out.println("Couldn't get an extranet Url from Site Prefs");

}

%>

<div class="siteMapcontent">

<div class="col">

<c:forEach items="${cib_navigationLinks}" var="cib_navLink_1" end="${cib_cursor}">

<h2 class="sitemap"><span class="dip" style="background-image:url(<c:out value="${cib_navLink_1.iconPath}"/>); background-position: left; background-repeat: no-repeat; !important;"></span>

<a href="<c:out value="${cib_navLink_1.path}"/>"><c:out value="${cib_navLink_1.text}" escapeXml="false" /></a>

</h2>

<c:if test="${cib_navLink_1.subLinks != null && cib_navLink_1.numSubLinks > 0}">

<ul class="itemList">

<c:forEach items="${cib_navLink_1.subLinks}" var="cib_navLink_2">

<li><a href="<c:out value="${cib_navLink_2.path}"/>"><c:out value="${cib_navLink_2.text}" escapeXml="false"/></a>

<c:if test="${cib_navLink_2.subLinks != null && cib_navLink_2.numSubLinks > 0}">

<ul class="subitemlist">

<c:forEach items="${cib_navLink_2.subLinks}" var="cib_navLink_3">

<li><a href="<c:out value="${cib_navLink_3.path}"/>"><c:out value="${cib_navLink_3.text}" escapeXml="false"/></a></li>

</c:forEach>

</ul>

</c:if>

</li>

</c:forEach>

</ul>

</c:if>

</c:forEach>

</div>

</div>

regards

chris

[3617 byte] By [jonesy21a] at [2007-10-2 12:55:59]
# 1

You havent mentioned what's the error you were getting or why it isnt working. Also I see no String comparisons in the posted code.

In general if you have an attribute say, 'cib_navLink' and you want to check if it starts with another attribute extranetUrl, you use the function taglib.

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<c:if test="${fn:startsWith(cib_navLink, extranetUrl)}">

Process

</c:if>

And if you want to test it with a String literal, say, "str", then

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<c:if test="${fn:startsWith(cib_navLink, 'str')}">

Process

</c:if>

Hope that helps.

Ram.

Madathil_Prasada at 2007-7-13 10:11:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...