Reputation: 689
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
Upvotes: 0
Views: 79
Reputation: 1610
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.
Upvotes: 2