如何使用Spring动态取值?
我有一个表单以及一个添加新行按钮。每行由不同的字段组成。现在我已经在命令 bean 中定义了上述字段的 ArrayList。我的问题是如何在运行时动态获取新值并将其绑定到我的 bean。我想添加一个动态生成的列表并将其发回以将其保存在数据库中。如何实现这一目标?
例如,我的表单包含三个文本区域,并且有一个添加按钮。现在,当我单击添加按钮时,前端会动态生成三个文本字段。现在我必须将它绑定到我的 bean,我已经在其中声明了这三个文本区域的数组列表。现在我应该如何实现这一目标。我的 ArryList 如下..
private ArrayList<CommText> commText;
CommText 类具有这三个变量
class CommText
{
private String text1;
private String text2;
private String text3;
//Getters and Setters...
}
I have a form along with a add new row button. Each row consist of different fields. Now I have already defined an ArrayList of the above fields in the command bean. My problem is that how can I dynamically take in new values and bind it to my bean during the runtime. I want to add a dynamically generated list and post it back to save it in the database. How to achieve this?
For example I have form with three text areas and there is an add button. Now when I click the add button there is a dynamic generation of the three text fields on the front end. and now I have to bind it to my bean where I have declared and arraylist for this three text areas. Now how should I achieve this. My ArryList is as follows..
private ArrayList<CommText> commText;
and the class CommText has these three variables
class CommText
{
private String text1;
private String text2;
private String text3;
//Getters and Setters...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 JavaScript
Ajax
框架(例如 JQuery)将其发布到您的Controller
,后者可以更新您的集合。您使用的是哪个版本的 spring-mvc/webflow?
Try using a javascript
Ajax
framework such as JQuery to post this to yourController
, which can in turn update your collection.Which version of spring-mvc / webflow are you using?