值未从 jsp 绑定到 Struts 中的操作 class 2

Values not getting binded from jsp to action class in Struts 2

我正在开发 Struts2 网络应用程序,目前我正面临表单绑定问题。从 jsp 到操作 class 的绑定无效。

场景是我有一个列表,该列表是根据上一个操作设置的。在当前 jsp 中,我遍历列表并在 jsp 中打印 Table 中的值。由于要求我应该使字段可编辑,以便用户可以编辑显示的值并将更新的值提交给下一个操作。

问题是我从 jsp 编辑的值没有绑定到正在运行的列表 class。我尝试了多种方法,但直到现在都没有运气。以下是我尝试过的方法。

我试过的第一种方法值没有被绑定:

<s:iterator value="list1" var="sVO" status="rowStatus">
    <tr onclick="SelIndex('<s:property value="itm_id"/>');">
        <td><s:property value="itm_id"/></td>
        <td><s:date name="proc_d" format="MM/dd/YYYY"/></td>
        <td><span style="display:none;"><s:property value="pln_n_n"/></span><input type="text" size = "8" value="<s:property value="pln_n_n"/>"/></td>
        <td><span style="display:none;"><s:date name="trd_d" format="MM/dd/YYYY"/></span><input type="text" size = "8" class="dateFilter" value="<s:date name="trd_d" format="MM/dd/YYYY"/>"/></td>
        <td><s:select theme="simple" name="list1[%{rowStatus.index}].vari_ty" id="tranType" list="liTTypes" headerKey="None" value="vari_ty" listKey="key1" listValue="value1" /></td>
        <td><span style="display:none;"><s:property value="description"/></span><input type="text" size = "8" value="<s:property value="description"/>"/></td>
        <td><s:property value="getText('format.money',{quantity})"/></td>
        <td><span style="display:none;"><s:property value="getText('format.money',{price})"/></span><input type="text" size = "10"  value="<s:property value="getText('format.money',{price})"/>"/></td>
    </tr>
</s:iterator

我尝试的第二种方法是不受约束的值:

<s:iterator value="list1" var="sVO" status="rowStatus">
    <tr onclick="SelIndex('<s:property value="itm_id"/>');">
        <td><s:property value="itm_id"/></td>
        <td><s:date name="proc_d" format="MM/dd/YYYY"/></td>
        <td><span style="display:none;"><s:property value="pln_n_n"/></span>
            <input type="text" name="list1[%{#rowStatus.index}].pln_n_n" value="<s:property value="pln_n_n"/>"/></td>
        <td><span style="display:none;"><s:date name="trd_d" format="MM/dd/YYYY"/></span>
            <input type="text" size = "8" name="list1[%{#rowStatus.index}].trd_d" class="dateFilter" value="<s:date name="trd_d" format="MM/dd/YYYY"/>"/></td>
        <td><s:select theme="simple" name="list1[%{rowStatus.index}].vari_ty" id="tranType" list="liTTypes" headerKey="None" value="vari_ty" listKey="key1" listValue="value1" /></td>
        <td><span style="display:none;"><s:property value="description"/></span>
            <input type="text" name="list1[%{#rowStatus.index}].description" size = "8" value="<s:property value="description"/>"/></td>
        <td><s:property value="getText('format.money',{quantity})"/></td>
        <td><span style="display:none;"><s:property value="getText('format.money',{price})"/></span>
            <input type="text" name="list1[%{#rowStatus.index}].price" size = "10"  value="<s:property value="getText('format.money',{price})"/>"/></td>
    </tr>
</s:iterator>

下面是我class

的动作
 public class testAction extends BaseAction 
    {

private List<ProcessVO> list1 = null;
   // getters and setters for list1 


   public String ListPage() throws AppException
     {
        String strReturn = "SUCCESS";           
    // This the method from which the list1 is populated   }

   public String ListPageSave() throws AppException
    {
        String strReturn = "SUCCESS";

    // This the method where i need the updated values from list1
    // values are not getting bound when this method is called from the page which is having Iterator tag,
     }

}

  BaseAction:

   public class BaseAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware, ServletContextAware {

/**
 * 
 */
private static final long serialVersionUID = 1L;

/**
 * HTTP Request object.

} ProcessVO 包含属性以及每个属性的 getter 和 setter。

任何人都可以告诉我这里的问题是什么。我正在使用需要更新的相同 list1 对象。任何帮助对我来说都非常有用,因为我遇到了这个问题。

<input type = "text" 
       name = "list1[%{#rowStatus.index}].pln_n_n" 
      value = "<s:property value="pln_n_n"/>"/>

如果您使用 HTML 标签,OGNL 将无法在其中工作。

您需要使用 <s:property/>:

<input type = "text" 
       name = "list1[<s:property value="%{#rowStatus.index}"/>].pln_n_n" 
      value = "<s:property value="pln_n_n"/>"/>

或使用 Struts2 标签,其中 OGNL 起作用:

<s:textfield name = "list1[%{#rowStatus.index}].pln_n_n"
            value = "pln_n_n" />

旁注:

  1. value 如果 name
  2. 没有 不同,则不需要
  3. value
  4. "SUCCESS"违反约定,应该是"success"(由SUCCESS常量映射)