Struts2:创建任意数量的对象的形式
所以我有一个对象,我想向其中添加一堆子对象(数量未定——用户只是一直说“再添加一个”)。 (即我有一个迭代器,我想用对象填充它)。
该项目是struts2,所以我有一个JSP,它将一个表单发送到一个操作类,该操作类实例化一些对象并将它们保存到数据库中。现在我还需要实例化并保存任意数量的对象。我不能只使用迭代器,因为我不知道将涉及多少个对象,而且我在从 Struts2 表单获取单个对象并将其放入迭代器时遇到困难。
有什么好的方法可以做到这一点,最好在我的jsps中没有java吗?
谢谢!
So I have an object and I want to add a bunch of sub-objects to it (an undetermined number-- the user just keeps saying "add one more"). (ie I have an iterator and I'd like to fill it with objects).
The project is struts2 so I've got a JSP which sends a form to an action class, which instatiates some objects and saves them to a database. Now I need to also instatiate and save an arbitrary number of objects. I can't just use an iterator because I don't know how many objects are going to be involved, and I'm having trouble getting an individual object from a Struts2 form and into the iterator.
Any ideas on a good way to do this, preferrably without java in my jsps?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要一个“添加一个操作”,用户可以使用子对象的详细信息重复调用该操作。然后,当您添加所有子对象时,您将调用不同的操作,将子对象的父级和子级集合保存到数据库中。
It sounds like you need an 'Add one more action' which the user calls repeatedly with the details of the sub object. Then when you've added all your sub objects you call a different action which saves the Parent and child Collection of sub objects to the database.