Min Chen
Min Chen

Reputation: 55

How to make HTML input checkbox checked by default in Struts 2?

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 <s: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"/>

Upvotes: 0

Views: 1015

Answers (1)

Roman C
Roman C

Reputation: 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>

Upvotes: 1

Related Questions