如何使用 Struts2 和 Jquery 预填充复选框?
我正在尝试确定预填充使用 Struts2 表单标签创建的某些复选框的最佳/最简单方法。我的应用程序是一个“正常”的三层设置,在控制器层使用 Struts2。
在我真正深入挖掘之前,标签是否支持创建所有可能的复选框的列表,然后填充它(例如,通过以下操作)?
示例操作:(
public class UserManagementAction extends ActionSupport implements Preparable {
private List<String> allRoles;
private List<String> rolesToPrepopulate;
// get/set methods
public void prepare() throws Exception {
// populate the allRoles and rolesToPrepopulate lists
}
public String execute() throws Exception {
return INPUT;
}
注意:假设 struts.xml 已配置为返回 INPUT 的 JSP)
感谢您的帮助。
贾森
I am trying to determine the best/easiest way to prepopulate certain checkboxes created using Struts2 form tags. My application is a "normal" three tier setup, using Struts2 on the controller layer.
Before I really, really dig deep here, does the tag support creating the list of all possible checkboxes, then populating it (say, via the below action)?
Sample action:
public class UserManagementAction extends ActionSupport implements Preparable {
private List<String> allRoles;
private List<String> rolesToPrepopulate;
// get/set methods
public void prepare() throws Exception {
// populate the allRoles and rolesToPrepopulate lists
}
public String execute() throws Exception {
return INPUT;
}
(Note: assume that struts.xml has been configured with which JSP to return for INPUT)
Thanks for any help.
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要做的是一个新的对象类并将其用作复选框。
例如:
在
prepare()
方法中,您可以根据需要设置selected
字段(以及所有id
字段)。接下来在 JSP 中:
然后在提交操作中选择的集合将填充 id。
也许经过一些修正它会起作用,但主要思想就在这里。
What I would do is a new object class and use it as for checkboxes.
For example:
And in
prepare()
method you can setselected
field as you wish (and alsoid
to all of them).Next in JSP:
And then in submit action Collection selected will be filled with ids.
Maybe with some corrections it will work, but the main idea is here.