如何识别用户选择哪一个?

时间:2010-01-31 10:37:19

标签: java javascript jsp servlets struts

我在jsp上的请求中有两个列表。第一个是productGroupName,第二个是products。

现在,我在下面展示这些。

<html:form action="/priceOrder"> <table width="100%" id="tableStyle" style="font: message-box;padding: 20px;">
        <logic:iterate id="productGroups" name="productGroup">
        <tr>
            <td>
            <h3 style="background-color: #720D00; color: white;"><bean:write
                name="productGroups" property="prodGroupName" /></h3>
            <table width="100%" id="tableStyle" style="font: message-box; color: white; padding: 20px; background: #F15A00;">
                <tr>
                    <td width="200px"><strong>Product Name</strong></td>
                    <td width="100px"><strong>How Many</strong></td>
                    <td><strong>Info</strong></td>
                </tr>
                <logic:iterate id="product" name="products">
                <tr>
                    <c:if test="${(productGroups.prodGroupID) == (product.prodGroupID)}">
                        <td>
                            <html:checkbox property="productChecked"  ><bean:write name="product" property="prodName"/></html:checkbox>                                 <br />
                        </td>
                        <td><html:text property="quantity" styleId="check"  size="5"/></td>
                        <td><bean:write name="product" property="prodDesc" /></td>
                    </c:if>
                </tr>
                </logic:iterate>
            </table>
            </td>
        </tr>
    </logic:iterate>

        <tr align="center" style="background-color: #F15A00;"><td height="50px">
              <html:submit styleId="buton" property="method"><bean:message key="button.order" /></html:submit>
        </td></tr>
        <tr><td></td></tr>
    </table></html:form>

正如您所见,我首先迭代productGroupNames,显示productID是否等于productGroupName下的productGroupID。但我在获取复选框和数量信息时遇到问题。我需要检查哪种产品以及需要多少产品。

2 个答案:

答案 0 :(得分:0)

我不做Struts,但他们的文档至少说你需要<html:multibox>

答案 1 :(得分:0)

不是直接提交表单,而是通过JS函数提交。在你的JS函数中,由于你正在迭代你的列表并给复选框和文本字段指定相同的名称,你将获得一个具有相同名称的数组。 那就是你将获得一系列ID。您可以获取所选复选框的索引,获取数量,获取相应的列表元素,并使用该值填充单独的隐藏表单变量。然后提交。

另一种方法是让每个复选框都有一个隐藏变量,它在列表和复选框之间提供一些映射。