tags:

views:

29

answers:

1

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.

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>

or is there some better way to do this?

+1  A: 

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

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

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.

BalusC