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!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
psms
  • 851
  • 3
  • 18
  • 35
  • did you declaired jstl? i.e. `<%@ taglib prefi x=”c” uri=”http://java.sun.com/jsp/jstl/core” %>` – Laurence Geng Aug 26 '14 at 04:54
  • 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: http://stackoverflow.com/questions/14454261/rendered-attribute-not-working-on-a-character-property/14457612#14457612 – BalusC Aug 26 '14 at 05:19

3 Answers3

16

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>
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
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.)

Aadil
  • 189
  • 4
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}

Nirav Prajapati
  • 2,987
  • 27
  • 32