4

In my jsp page I am specifying:

<c:choose>
line 1: <c:when test="${com.community_classification_id.contains('1')}">
            <input type="checkbox" id="by_invitation1"   name="invitaion" value="1" checked="true">By Invitation<span style="padding-left:28px"></span>
        </c:when>
        <c:otherwise>
            <input type="checkbox" id="by_invitation1"   name="invitaion" value="1">By Invitation<span style="padding-left:28px"></span>
        </c:otherwise>
</c:choose>

but @line no. 1 it gives me 500 error with

The function contains must be used with a prefix when a default namespace is not specified

I am not able to understand it. What is wrong?

tomrozb
  • 25,773
  • 31
  • 101
  • 122
ASUR
  • 405
  • 4
  • 10
  • 23

2 Answers2

6

Check this out: JSTL fn:contains() function

Used to find a String inside another one (I guess this is you are trying to achieve)

In your code:

<c:choose>
    <c:when test="${fn:contains(com.community_classification_id, '1')}">
        <input type="checkbox" id="by_invitation1" name="invitaion" value="1" checked="true">By Invitation<span style="padding-left:28px"></span>
    </c:when>
    <c:otherwise>
        <input type="checkbox" id="by_invitation1" name="invitaion" value="1">By Invitation<span style="padding-left:28px"></span>
    </c:otherwise>
</c:choose>

Don't forget to include the taglib in your JSP to use it:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jelies
  • 9,110
  • 5
  • 50
  • 65
  • I don't understand... my answer helped you but you accepted the other one? It's a mistake? XD – jelies Jul 30 '12 at 11:56
1

You can use your static method in EL (which I assume com.community_classification_id.contains is) but first you have to define custom EL function.

Check this answer and this answer which shows how to create and use EL functions in JSP. Then just remember to import your taglib and use your static method with prefix like shown in those answers.

Community
  • 1
  • 1
Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112