Possible Duplicate:
Evaluate empty or null JSTL c tags
I'm refactoring scriptlets to JSTL and EL and I would like to know how to write the following in JSTL / EL:
if(sokandeList != null && sokandeList.size() > 0) { %>
...
I don't know how to test for null and AFAIK EL can only access getters in this context so I must add a method getSize() to the sokandeList class. Correct? What should the JSTL / EL expression look like? Thanks for any help
Use the empty
keyword, it checks both nullness and emptiness.
<c:if test="${not empty sokandeList}">
...
</c:if>
Note that when your intent is to iterate over the list using <c:forEach>
then it may be good to know that it already won't run when the provided items
is empty
. If the <c:forEach>
is directly surrounded by this check, then this check is entirely superfluous.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With