【问题标题】:How can recognize user selected which ones?如何识别用户选择了哪些?
【发布时间】:2011-01-11 09:30:42
【问题描述】:

我对 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。但我在获取复选框和数量信息时遇到问题。我需要检查哪种产品以及需要多少。

【问题讨论】:

    标签: java javascript jsp servlets struts


    【解决方案1】:

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

    另一种方法是为每个复选框关联一个隐藏变量,该变量提供列表和复选框之间的某种映射。

    【讨论】:

      【解决方案2】:

      我不使用 Struts,但他们的文档至少说您需要&lt;html:multibox&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-06
        • 1970-01-01
        • 2018-03-11
        • 2012-01-12
        • 1970-01-01
        • 1970-01-01
        • 2017-03-29
        • 2011-03-29
        相关资源
        最近更新 更多