I have one List. Which is fetch from java class to jsp page. I want to display this List in jsp page but, if List is empty then display one error message otherwise display List's item.
<s:iterator value="productList">
<tr style="background-color: #99CCFF">
<td><s:property value="pid"/></td>
<td><s:property value="productname"/></td>
<td><s:property value="producttype"/></td>
<td><s:property value="productprice"/></td>
<td><s:property value="shopname"/></td>
<td><s:property value="productcity"/></td>
<td><s:property alue="ownername"/></td>
</tr>
</s:iterator>
You can use Struts2 <s:if>
and <s:else>
tags for conditional checking like this:
<s:if test="%{getProductList().isEmpty()}">
Error
</s:if>
<s:else>
<s:iterator value="productList">
<tr style="background-color: #99CCFF">
<td><s:property value="pid"/></td>
<td><s:property value="productname"/></td>
<td><s:property value="producttype"/></td>
<td><s:property value="productprice"/></td>
<td><s:property value="shopname"/></td>
<td><s:property value="productcity"/></td>
<td><s:property alue="ownername"/></td>
</tr>
</s:iterator>
</s:else>
<s:if test="%{productList.isEmpty()}">
<tr>
<td colspan="7">Empty</td>
</tr>
</s:if>
<s:else>
<s:iterator value="productList">
<tr style="background-color: #99CCFF">
<td><s:property value="pid"/></td>
<td><s:property value="productname"/></td>
<td><s:property value="producttype"/></td>
<td><s:property value="productprice"/></td>
<td><s:property value="shopname"/></td>
<td><s:property value="productcity"/></td>
<td><s:property alue="ownername"/></td>
</tr>
</s:iterator>
</s:else>
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