【发布时间】:2012-01-09 21:41:00
【问题描述】:
我遇到了 Struts 1 表单的问题,该表单包含一个逻辑:迭代负责创建行,每个行都有一个输入按钮。 当我点击任何这些提交按钮时出现问题,动态数据未正确发布并且表单没有这些值,这是一个示例:
<html:form action="/myAction" styleClass="centeredForm" style="display:inline" >
<td class="formLabel">City</td>
<td class="formControl">
<bean:define id="cities" name="myForm"
property="cities" type="java.util.Collection"/>
<html:select styleClass="dashSelect" property="city">
<html:option value="">All Cities</html:option>
<html:options collection="cities"
property="id" labelProperty="value"/>
</html:select>
</td>
... Other elements ...
<logic:iterate id="myObject" name="myForm" property="myObjects" indexId="index" type="com.test.MyObject">
<% String rowClass = index.intValue() % 2 == 0 ? "even-row" : "odd-row"; %>
<tr class="<%=rowClass%>">
<td class="result-cell"><bean:write name="myObject" property="id" /> </td>
<td class="result-cell"><bean:write name="myObject" property="name" /> </td>
<td class="result-cell">
<html:select styleClass="dashSelect" name="myObject" property="status">
<html:option value="F">Disabled</html:option>
<html:option value="T">Enabled</html:option>
</html:select>
</td>
<td>
<html:submit/>
</td>
“城市”部分和逻辑之外的其余部分:迭代,在“myForm”上出现得很好,但“myObject”不是。我什至尝试使用 JavaScript 函数提交它,但无法使其正常工作。 目前,我所拥有的(我留下的那个 html:submit 作为参考)导致 POST 包含一堆“状态”参数和我之前提到的正确值。
任何人都可以对此有所了解吗?
如果您需要更多信息,请告诉我。
提前非常感谢!
【问题讨论】:
-
不确定你的意思;您没有使用
indexed标签(参见here)或嵌套标签,也没有手动构建索引属性名称——不过,我并不完全清楚什么不起作用。 (在某些标签/bean 中似乎也需要付出很多额外的努力;如果您使用的是过时的容器,您是否考虑过使用 JSP EL 或至少使用 EL Struts 标签?) -
问题是当我点击提交时,表单没有填充“myObject”,这是我通过逻辑创建的每一行的信息:迭代。在此期间,我将查看索引标签。
标签: jsp struts struts-1 struts-html struts1