<c: if> does not work for character comparison

<c:if> does not work for character comparison. The code is inside the table. Here is the code

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

When I use this code inside the table, the contents of the table are not displayed. Please, help!

+5
source share
3 answers

Problem: EL supports both double and single quotes. Therefore, 'U' is taken as a String , not a char . To fix the problem, you can use the charAt(0) method for this line:

 <c:if test="${record.type eq 'U'.charAt(0) }">Planned</c:if> 
+11
source

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 a version conflict, then

try below it can help

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

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

0
source

This works for me:

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

This works for me, because instead of the first 'U', I got a list of characters. Thus, the type must first be converted to String.)

0
source

Source: https://habr.com/ru/post/1201119/


All Articles