简体   繁体   中英

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}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM