<c:if> not working for comparing characters [duplicate]
Asked Answered
S

3

8

<c:if> is not working for comparing characters.The code is inside a table.Here is the code

<c:if test="${record.type eq 'U' }">Planned</c:if>

When I use this code inside the table,the table content is not displayed.Please help!

Scape answered 26/8, 2014 at 4:45 Comment(2)
did you declaired jstl? i.e. <%@ taglib prefi x=”c” uri=”http://java.sun.com/jsp/jstl/core” %>Swearword
Better use enums instead of chars. You can compare enums the "normal" way (exactly like as in your current attempt). Here's a more elaborate answer in JSF context: #14454761Oxytocic
A
17

Issue is EL supports both double and single quoted Strings. So 'U' is taken as String, not char. To resolve the issue, you can use charAt(0) method on that String:

<c:if test="${record.type eq 'U'.charAt(0) }">Planned</c:if>
Alicea answered 26/8, 2014 at 4:52 Comment(0)
R
1

This works for me:

`<c:if test="${'U'.toString() eq 'U'}">demo</c:if>`

It works for me since instead of first 'U', I was getting the list of Characters. So the type should be converted to String first.)

Rash answered 5/2, 2015 at 14:21 Comment(0)
K
0

check the value of ${record.type} print it on jsp

becuse

<c:if test="${'U' eq 'U'}">demo</c:if> 

it works for me in jsp

or if you have some version conflict then

try below one it may help

<c:if test = "${record.type == 'U'}">demo</c:if> 

but make sure the value of ${record.type}

Kiser answered 26/8, 2014 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.