在struts的索引属性中添加新项目
这就是我想做的: 我有一个带有索引属性(地区列表)的actionForm,我已成功显示并绑定所有项目以形成列表地区。
我想要一个 jsp 页面,允许用户添加和删除该列表中的项目。问题是struts使用例如districts[0]、districts[1]来绑定列表中的每个项目,当我想要添加或删除新项目时,这是否意味着我需要附加带有名称的新“input”标签='districts[last_index]' 在列表末尾使用javascript添加并删除相应索引的输入标签以进行删除?有替代方案吗?
here is what i want to do:
I have an actionForm with an indexed property(a list of districts), I have managed to show and bind all items to form the list districts.
I want to have a jsp page that allow user to add and delete item in that list. The problem is that struts use for example districts[0], districts[1] to bind each item in the list, when i want new item to be added or deleted, does this mean i need to append new 'input' tag with name='districts[last_index]' at the end of the list using javascript for addition and remove input tags for the corresponding index for deletion? is there alternative for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。这就是它的工作原理。我尝试过像这样管理参数并且工作得很好。并且,对于删除,您不需要重新索引项目。您只需要管理last_index。供您参考:
如果列表包含具有嵌套属性的对象,您需要实现它。否则,您只能获取列表中指定列表名称的项目。
例如:
对于
ListintegerInputs;
、&integerInputs=1&integerInputs=230&integerInputs=332
可以工作。对于
填充列表的 url 类似于
&myObjList[0].id=12&myObjList[0].name=testName1&myObjList[1].id=122&myObjList[1].name=仅测试名称
Yes. This is the way it works. I have tried managing parameters like this and has worked fine. And, for the deletion, you need not re-index the items. You just need to manage the last_index. For your information:
If the list contains objects with nested property, you need to implement this. Otherwise, you can just get the items in the list with the listname specified.
E.g.:
For
List<Integer> integerInputs;
,&integerInputs=1&integerInputs=230&integerInputs=332
will work.For
The url to populate the list would be something like
&myObjList[0].id=12&myObjList[0].name=testName1&myObjList[1].id=122&myObjList[1].name=testNameOnly