值未从jsp绑定到Struts

值未从jsp绑定到Struts

本文介绍了值未从jsp绑定到Struts 2中的操作类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在Struts2 Web应用程序上工作,目前我遇到表单绑定问题.从jsp到action类的绑定不起作用.

I am working on Struts2 web application and currently i am facing issue with the form binding. The binding from jsp to the action class is not working.

方案是我有一个从上一个动作设置的列表.在当前的jsp中,我遍历该列表并在jsp中的表中打印值.由于需要,我应该使这些字段可编辑,以便用户可以编辑显示的值并将更新的值提交到下一个动作.

The scenario is i am having a list which is being set from the previous action. In current jsp I am iterating over the list and printing the values in the Table in jsp. Due to a requirement i am supposed to make the fields editable so that user can edit the values displayed and submit the updated values to the next action.

问题是我从jsp编辑的值未绑定到动作类中的列表.我已经尝试了多种方法,但是到目前为止还没有运气.以下是我尝试过的方法.

The problem is that the values that i edit from the jsp are not being bound to the list in action class. I have tried multiple ways but no luck till now. below are the ways that i have tried.

我尝试值绑定的第一种方法:

The First way i tried values are not getting bound:

<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

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

The second way i tried values not getting bound:

<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>

下面是我拥有的动作课

 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包含属性以及每个属性的获取器和设置器.

}The ProcessVO contains the attributes and getters and setters for each attribute.

任何人都可以让我知道这里的问题是什么.我正在使用需要更新的相同list1对象.当我坚持这个问题时,任何帮助对我来说都是非常有用的.

Can anyone please let me know what is the issue here. I am using the same list1 object which needs to be updated. Any help will be very useful for me as i am stuck with this issue.

推荐答案

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

如果您使用HTML标记,OGNL将无法在其中使用.

If you use HTML tags, OGNL won't work inside them.

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

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

或使用Struts2标签(OGNL可以在其中使用该标签)

or use Struts2 Tags, where OGNL works:

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


旁注:


Side notes:

    如果
  1. valuename
  2. 没什么不同,则不需要
  3. value
  4. "SUCCESS"违反约定,应为"success"(由SUCCESS常量映射)
  1. value is not needed if it's not different from name, and
  2. "SUCCESS" is against the convention, it should be "success" (mapped by the SUCCESS constant)

这篇关于值未从jsp绑定到Struts 2中的操作类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:54