9

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 ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Umesh Patil
  • 10,475
  • 16
  • 52
  • 80

3 Answers3

10

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" %>
Roman C
  • 49,761
  • 33
  • 66
  • 176
4

WRONG#1: <c:if not test="${ some_bool }">MSG</c:if>

JasperException: equal symbol expected

WRONG#2: <c:if Not test="${ some_bool }">MSG</c:if>

JasperException: java.lang.ClassNotFoundException:

WRONG#3: <c:if test="${Not some_bool }">MSG</c:if>

ELException: Failed to parse the expression + JasperException: contains invalid expression(s):

WRONG#4: <c:if test=not"${ some_bool }">MSG</c:if>

JasperException: quote symbol expected

WRONG#5: <c:if test=Not"${ some_bool }">MSG</c:if>

JasperException: java.lang.ClassNotFoundException:

WRONG#6: <c:if test="${ ! some_bool }">MSG<c:if/>

JasperException: The end tag "</c:forEach" is unbalanced


CORRECT#1: <c:if test="${not some_bool }">MSG</c:if>

CORRECT#2: <c:if test="${ ! some_bool }">MSG</c:if>

KANJICODER
  • 3,611
  • 30
  • 17
2

whether certain text doesn't contain expression "Service include.."

You can use indexOf that return -1 if doesn't contain

${fn:indexOf(ruleDesc, 'Service include')==-1}

You can try ignore case as well

${fn:indexOf(ruleDesc.toLowerCase(), 'service include')==-1}

EDIT

please test it again at your end with below sample code:

<c:set var="ruleDesc" value="abc Service include abc" />
Not starts with: ${!fn:startsWith(ruleDesc, 'Service include')}
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76