【问题标题】:Struts 1 - Row submitStruts 1 - 行提交
【发布时间】: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" />&nbsp;</td>
      <td class="result-cell"><bean:write name="myObject" property="name" />&nbsp;</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


【解决方案1】:

我没有使用一个单一的表单,而是在逻辑中使用了一个表单:迭代,为相应的属性添加索引并使用 Javascript 函数来获取其余部分。

谢谢!

【讨论】:

    【解决方案2】:

    逻辑迭代:试试这个方法可能对你有帮助。

    <logic:iterate name="myForm" property="myObjects" id="myObjects" indexId="true">
      <tr>
       <td class="result-cell"><bean:write name="myObjects" property="id" />&nbsp;</td>
          <td class="result-cell"><bean:write name="myObjects" property="name"/>&nbsp;</td>
          <td>
            <html:submit/>
          </td>    
      </tr>
    </logic:iterate>
    

    【讨论】:

    • 您好 subodh,不幸的是, bean:write 没有值或索引属性。 :( 你是打算用另一个吗?非常感谢你的回复!
    • 哦!那么会发生什么,如果你没有使用值和索引,属性是否显示任何错误或输出是什么?请参阅我的更新答案尝试这样做,如果有任何问题,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多