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
emptykeyword, it checks both nullness and emptiness.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 provideditemsisempty. If the<c:forEach>is directly surrounded by this check, then this check is entirely superfluous.See also: