[英]How to retrieve the elements of HashSet using Struts2 tag without using s:iterator
[英]How to retrieve the data of <s:radio> within <s:iterator> tag into Struts2's action
我需要在網頁中執行以下操作:一排顯示問題和選擇的行,這些選擇由廣播按鈕組成。 我不知道如何將這些單選按鈕的數據放入我的Java代碼中。 這是我的jsp代碼:
<s:iterator value="questionsList" status="status" var="questionsList">
<tr>
<td><s:property value="title"/></td>
</tr>
<tr>
<td>
<s:radio list="{'A','B','C','D'}" name="[%{#status.index}]answer" theme="simple"/>
</td>
</tr>
</s:iterator>
我試過了
private List answer = new ArrayList();
answer = (List)request.getAttribute("[%{#status.index}]answer");
但這不起作用。 如果您還有其他方法可以這樣做,請告訴我,謝謝!
您可以為要在Java中獲取的列表提供索引的屬性名稱
<s:iterator value="questionsList" status="status">
<tr>
<td><s:property value="title"/></td>
</tr>
<tr>
<td>
<s:radio list="{'A','B','C','D'}" name="questionsList[%{#status.index}].answer" theme="simple"/>
</td>
</tr>
</s:iterator>
瞧! 您的問題列表將填充由status.index
變量提供的索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.