在struts(使用struts live)中进行多行更新的好方法是什么?
不使用 DynaForm 及其同类。
我想使用 POJO 数据传输对象,例如 Person:
public class Person {
private Long id;
private String firstName;
private String lastName;
// ... getters / setters for the fields
}
在 struts 实时操作表单中,我们将拥有:
public class PersonUpdateForm extends SLActionForm {
String organization;
Person[] persons; // all the people will be changed to this organization; they're names and so forth can be updated at the same time (stupid, but a client might desire this)
// getters / setters + index setters / getters for persons
}
JSP 中相应的 html:text 标记是什么样子才能允许这样做? 如果我切换到“列出人员”字段并使用延迟加载列表(在公共集合中),这会如何改变事情?
在 struts-1.2(.9?) 中似乎没有好的方法来做到这一点?
非常感谢所有帮助! 如果您需要更多背景信息,请告诉我,我可以提供一些。
Without using DynaForm and it's kin.
I would like to use a POJO data transfer object, e.g., Person:
public class Person {
private Long id;
private String firstName;
private String lastName;
// ... getters / setters for the fields
}
In the struts live action form we would have:
public class PersonUpdateForm extends SLActionForm {
String organization;
Person[] persons; // all the people will be changed to this organization; they're names and so forth can be updated at the same time (stupid, but a client might desire this)
// getters / setters + index setters / getters for persons
}
What would the corresponding html:text tags look like in the JSP to allow this? If I switch to a List persons field and use a lazy-loading list (in commons-collections) how would that change thinsg?
There seems to be no good way to do this in struts-1.2(.9?)
All help is greatly appreciated!!! If you need more context let me know and I can provide some.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我相信我已经弄清楚了! 诀窍是让索引 getter 在每次 BeanUtils 的 populate 方法调用 getPersons() 方法时创建一个元素。 代码尚未完成,但我得到了一个积极的结果。 现在是 3:30,我已经被这个问题困住了一段时间了。 似乎没有人知道答案,这让我想用鳟鱼打他们的头。 至于我自己的无知……只能怪他们了!
当然,还要添加索引的 getter 和 setter。
我记得我实际上是如何做到这一点的。 您必须将上面的人员列表预先初始化为您希望转移的最大大小。 这是因为 List 首先被转换为数组,然后在数组的每个元素上设置属性,最后使用 setPersons(...) 返回 List。 因此,使用延迟加载列表实现或类似方法(如上面所示)将不适用于 struts live。 以下是您需要做的更详细的事情:
这基本上就是您必须做的! 但真正的问题是 - 谁还在使用 struts live?!
Okay, I believe I've figured it out! The trick is to have your indexed getter create an element each time the getPersons() method is called by the populate method of BeanUtils. The code is completed yet, but I got a positive looking result. It's 3:30 and I've been stuck on this a while. Nobody seemded to know the answer, which makes me want to smack them in the head with a trout. As for my own ignorance ... I only have them to blame!
Add your indexed getters and setters too, of course.
I remember how I actually did this. You must pre-initialize the persons List above to the maximum size you expect to transfer. This is because the List is first converted to an array, the properties then set on each element of the array, and finally the List set back using setPersons(...). Therefore, using a lazy-loading List implementation or similar approach (such as that show above) will NOT work with struts live. Here's what you need to do in more detail:
That's basically what you have to do! But the real question is - who's using struts live anymore?!