I have the following code in my JSP , Im using Struts2
<s:iterator value="incentiveList" status="stat">
<tr>
<td><s:checkbox name="checkboxes[%{#stat.index}]" theme="simple" /></td>
<td></td>
<td><s:property value="marketingAmount" /> <s:hidden value="%{incentiveList.marketingAmount}" /></td>
<td></td>
<td></td>
<td></td>
<td><s:property value="marketingIncentive" /></td>
<td></td>
<td></td>
<td></td>
<td><s:property value="advertizingIncentive" /></td>
<td></td>
<td></td>
<td><s:property value="channelPlacementIncentive" /></td>
<td></td>
</tr>
</s:iterator>
</table>
</br>
</br>
<s:if test="#status.index gt 0">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()'/>
</s:if>
<s:else>
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</s:else>
Now I want to enable submitButton if incentiveList above has any value i.e count gt 0 and to achieve this I used below code
<s:if test="#status.index gt 0">
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()'/>
</s:if>
<s:else>
<s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
</s:else>
but it is not working , please correct if anything is missed out
If incentiveList
has no values, you won't get anything, not only the buttons. You will endd up with invalid <table></table>
code, then the <s:if>
should be put around the iterator too:
<s:if test="incentiveList.size()>0">
<!-- iterator here -->
<!-- buttons here -->
</s:if>
P.S: IteratorStatus is iterator-scoped (and iteration-scoped), it won't exist outside the Iterator, and it would be useless since it carries informations about the currently iterated element