本文介绍了如何使用Struts2更新JSP上显示的列表的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts2在JSP上显示对象列表的内容.事件流如下:

I'm using Struts2 to display the contents of a list of objects on a JSP.The flow of events is as following:

  1. GetDataAction.java ->从以下位置获取值数据库,填写ArrayList名为tableList.成功之后,显示displayData.jsp.
  2. displayData.jsp ->使用s:iterate标记显示对象的值在tableList中.
  3. 用户更改了displayData.jsp并按更新按钮.在点击更新按钮, UpdateDataAction.java 被调用.
  1. GetDataAction.java -> fetches values fromthe database, fills in the ArrayListnamed tableList. On success, thedisplayData.jsp is shown.
  2. displayData.jsp -> uses the s:iterate tag to display the values of objectsin the tableList.
  3. The user changes some values in thedisplayData.jsp and presses on theUpdate button. On the click ofUpdate button, theUpdateDataAction.java is called.

现在我的问题是;如何在UpdateDataAction.java中使用相同的tableList来获取修改后的值?我尝试在UpdateDataAction.java中声明一个具有相同名称'tableList'的ArrayList(以及getter和setters),但是它抛出NullPointerException.

Now my problem is; How do I use the same tableList in UpdateDataAction.java to get the modified values?I tried declaring an ArrayList with the same name 'tableList' (along with getters and setters), in UpdateDataAction.java but it throws a NullPointerException.

请提出建议.

推荐答案

IMO的更新方式不是一个好主意.您应该将每一行链接到单独的编辑页面或使用ajax.有许多可用的插件使用ajax更新表值,如果需要,我可以为您提供链接回到您的操作方式,我想您正在按照以下步骤进行操作

IMO the way you are updating is not a good idea.Either you should link every row to a seperate edit page or use ajax.There are many plugins available to update table values using ajax,If you need i can provide you the linksBack to your way of doing it,i guess you are doing it as follows

<s:form action="UpdateDataActionName">
<s:iterator value="tableList">
<s:textfield name="objectName.propertyName1" value="%(propertyName1)">
<s:textfield name="objectName.propertyName2" value="%(propertyName2)">
<s:textfield name="objectName.propertyName3" value="%(propertyName3)">
</s:iterator>
<s:submit value="Update"/>
</s:form>

现在在您的UpdateDataAction中声明一个类型为<objectNameoftableListType>的列表,即tabeList表示的对象类型相同.列表的名称必须为objectName.尝试Iteate并检查是否获得了从jsp提交的正确值.

Now declare a list in your UpdateDataAction,of type <objectNameoftableListType> i.e. the same object type which the tabeList is representing.The name of the list must be objectName.Try to Iteate and check if you are getting the right values as submitted from the jsp.

这篇关于如何使用Struts2更新JSP上显示的列表的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:14