Skip to content
Advertisement

Struts2 Tags Radio button

I have this iterator that loops through an object.

        <s:iterator value = "choices" status = "key">
        <s:set var = "test" value ="%{#key.index}"/>
             <input type = "radio" name="choices[{key.index}].answer" />
             <s:textfield name = "choices[%{#key.index}].value" value = "%{choices[%{#key.index}].value}"/>
            <br>
        </s:iterator>

where answer is a boolean value, that I am trying to set through radio buttons.

but the problem is, upon on the generated html, teh radio buttons. is like this

<input type = "radio" name="choices[%{#key.index}].answer" />

It did not have the indice/index. it only gave me the %{#key.index}

Advertisement

Answer

you have to use property tag to get the actual value

<input type = "radio" name="<s:property value='%{choices[#key.index].answer}' />" />

Better use radio tag of struts tag library, like this

<s:radio name="choices[%{#key.index}].answer" / >
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement