Tag Archives: tag

How to know if a List’s size in Struts2 tag

In my last project, I forgot to judge the list’s size before loop it. So I got an Exception. Then I googled the following solutions.

1. To know if it’s empty:

<s:if test="%{productList.isEmpty()}">
    //if the list is empty
</s:if>
<s:else>
    <s:iterator value="productList">
      //if not empty, then do the loop
    </s:iterator>
</s:else>

2. To know its size

<s:if test="%{productList.size() > 0}">
    //do the loop
</s:if>