多个单选按钮选择 [英] multiple radio button selection

查看:77
本文介绍了多个单选按钮选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须显示很多组,并且每个组下都有很多产品.为了显示它们,我使用JSTL从组列表中迭代产品列表. 用户可以通过单击收音机从每个组中选择一种产品.为了实现这一点,我添加了带有无线电名称的组的ID,以便用户可以选择多个无线电.

I've to display many groups and many products under each group. For displying them I'm using JSTL to iterate the list of products from the list of groups. User can select one product from each group by clicking on the radio. To enable this i've added the id of the group with the radio name, so that user can select multiple radios.

如何从servlet获取选定的无线电?因为名称是动态创建的.

How can get the selected radios from the servlet? Because the name is created dynamically.

<c:forEach items="${pgb.tableValues}" var="tv">
   <tr>
     <c:forEach items="${tv}" var="tvalue">
        <c:if test="${tvalue.type != null && not empty(tvalue.type)}">
           <td>
            <c:if test="${tvalue.type=='radio'}">
              <input type="radio" value="${tvalue.id}" name="selectedProd${pgb.id}"/>
            </c:if>
            <c:if test="${tvalue.image != null}">
                <img src="${tvalue.image}" alt="image"/>
            </c:if>
            ${tvalue.text}
          </td>
        </c:if>
     </c:forEach>
    </tr>
</c:forEach>

或者有更好的方法吗?

推荐答案

只需使用与您在HTML中指定的名称相同的名称即可获取它们.

Just get them by same name as you specified in the HTML.

String selected = request.getParameter("selectedProd" + pgb.getId());


顺便说一句,${tvalue.type != null && not empty(tvalue.type)}可以缩短为${not empty tvalue.type}. empty还会检查null.


By the way, the ${tvalue.type != null && not empty(tvalue.type)} can be shortened to ${not empty tvalue.type}. The empty also checks for null.

这篇关于多个单选按钮选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆