1

I have a checkbox in JSP, which consists of a HashMap<String, String>, e.g.,

"1", "Name"
"2", "Age"
"3", "Gender"

Now I want the first entry be checked by default, how should I write the if test code? The current code is as follows:

<input type="checkbox" name="params" value="<s:property value="#param.key"/>"
<s:iterator value="params" var="app">
<s:if test="???">
onclick="return false"
checked="checked"
</s:if>
</s:iterator>/>
&emsp;<s:property value="#param.value"/>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Min Chen
  • 75
  • 1
  • 6

1 Answers1

1

The <s:iterator> tag has a status attribute were you can use a variable

<s:iterator value="params" var="app" status="paramStatus">
<s:if test="#paramSatus.index == 0">
onclick="return false"
checked="checked"
</s:if>
</s:iterator>
Roman C
  • 49,761
  • 33
  • 66
  • 176