从索引属性中删除项目 - JavaBeans 问题
我正在使用索引属性(使用 struts 和 java/jsp)。我们有一个动态表,可以在表中添加/删除行/项目。添加行按预期工作 - 我在操作类的表单中看到新行。删除的行不会被设置(显然),但它们也不会从列表中删除。我已经实现了 void setItem(List)、void setItem(index)、Item getItem(index) 和 List getItem() 方法。我找不到有关索引属性行为的太多信息。是否有我需要实现的重置方法,或者索引属性是否应该负责设置新列表?据我所知,只有仍在列表中的项目被设置,并且它们是使用 void setItem(Item) 方法设置的。
I'm working with indexed properties (using struts and java/jsp). We have a dynamic table that can add/delete rows/items in the table. The adding of rows works as intended - I see the new rows in the form in the action class. The deleted rows do not get set (obviously), but they are also not removed from the list. I have implemented a void setItem(List), void setItem(index), Item getItem(index) and List getItem() methods. I can't find much information regarding the behavior of indexed properties. Is there a reset method that I need to implement, or are indexed properties supposed to take care of setting a new list? From what I can tell, only the items still in the list are set, and they're set using the void setItem(Item) method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如:
然后您可以在 JSP 中显示/编辑列表,如下所示:
如果要向列表中添加元素,请确保设置的索引高于最大索引。例如,如果我的列表包含 3 个元素,则新元素(第四个)将如下所示:(请记住,列表是基于零索引的)
提交表单时,删除的任何列表元素都将在特定索引处设置 null。例如,假设用户删除了第二个元素,我将在服务器上看到:
For example:
Then you can display/edit the list in your JSP like so:
If you want to add elements to the list, make sure you set an index superior than the maximum one. For example if my list contains 3 elements, the new one (the fourth) will look like this: (remember that list are zero-index based)
When the form is submitted, any list element deleted will set a null at the specific index. For example, let's say the user deletes the 2nd elements, I will see on the server: