Question

Is there any difference on evaluating a String object on JSTL between

<c:if test="${empty aString}"></c:if>

and

<c:if test="${aString.isEmpty()}"></c:if>

?

EDIT: Both works, .isEmpty() gives an anotation error on Spring Tool Suite

Was it helpful?

Solution

The code as you have it, both are calculated as false because you have a whitespace inside your test " "

test=" true" <!-- condition is calculated as false -->
test="true" <!-- condition is true -->

Moreover to call method from jstl you have to call it withour get or is prefix. e.g. ${var.empty} calls isEmpty or getEmpty of var object.

Edit

It will be better approach ${empty var}, because it's true either var is '' or null. empty covers and null conditions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top