Error using EL in JSP: "The function contains must be used with a prefix when a default namespace is not specified"

11,736

Solution 1

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" %>

Solution 2

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.

Share:
11,736

Related videos on Youtube

ASUR
Author by

ASUR

I am a JAVA developer.

Updated on September 14, 2022

Comments

  • ASUR
    ASUR over 1 year

    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?

  • jelies
    jelies over 11 years
    I don't understand... my answer helped you but you accepted the other one? It's a mistake? XD