JSTL Expression for test if Not

Umesh Patil picture Umesh Patil · Jul 23, 2014 · Viewed 25.5k times · Source

I am trying to know whether certain text starts with an expression "Service include.." using JSTL condition. However, I see that this expression is incorrect and error some. Can you please identify what is wrong with this.

Below is part of JSP page.

<%--  
    Attributes: ruleView
    RuleViewDto ruleView
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ruleDesc" value="${rule.description}"/>

<c:if test="${!fn:startsWith(ruleDesc, 'Service include')}">        

    <td align="right"  class="imgButton"
        onclick="RuleSet.removeRule('${ruleView.stepId}', '${rule.code}');" style="padding-left: 10px; padding-right: 10px;" 
        ><img src="../img/delete.gif" /></td>
</c:if>

What is wrong with Expression ${!fn:startsWith(ruleDesc, 'Service include')} ? How how should it be ?

Answer

Roman C picture Roman C · Jul 23, 2014

What is wrong with Expression ${!fn:startsWith(ruleDesc, 'Service include')}

the expression itself looks good, one thing you didn't specify in the JSP is a taglib used for fn namespace. Add this taglib definition at beginning of the JSP page.

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