struts2的checkboxlist中如何保留值?
大家好,我正在为 Struts2 应用程序的 JSP 中的字段做复选框列表。
JSP 中的代码:
<s:checkboxlist list="subjectList" name="subjects"/>
操作类:
I have used some if/else condition to get the selected checkbox values in Action class as follows.
if(this.getSubjects().trim().contains("CSC"))
subject.setCSC("true");
else
subject.setCSC("false");
if(this.getSubjects().trim().contains("ECE"))
subject.setECE("true");
else
subject.setECE("false");
将输出对象主题存储在数据库中。它工作正常。 表中有字段 CSC(true/false)、ECE(true/false) 等。
现在我想保留复选框列表选项,就像数据库值一样。如果该字段为 true,则它必须处于 SELECTED 状态,如果该字段为 false,则在 Jsp 中它应该处于 UNSELECTED 状态。
那么如何从数据库值中保留复选框列表中的值。如果是单个checkbox可以方便的设置value字段。如果是列表框如何进行。
欢迎对此任务提出更多建议。提前致谢!!!
Hi all I am doing checkbox list for a field in JSP of Struts2 application.
Code in JSP:
<s:checkboxlist list="subjectList" name="subjects"/>
In action Class:
I have used some if/else condition to get the selected checkbox values in Action class as follows.
if(this.getSubjects().trim().contains("CSC"))
subject.setCSC("true");
else
subject.setCSC("false");
if(this.getSubjects().trim().contains("ECE"))
subject.setECE("true");
else
subject.setECE("false");
Storing the output object subject in Database. It working fine.
In Table have the fields CSC(true/false), ECE(true/false) like that.
Now i want to retain the checkboxlist options as like database value. If the field is true it have to be in SELECTED, if the field is false it should be UNSELECTED in Jsp.
So how to retain the values in checkboxlist from database values. If it is a single checkbox can easily set the value field. If it is list box how to proceed.
Welcome to more suggestion for this task. Thanks in Advance!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种简单的解决方案是创建两个列表(
arrayList
或任何基于集合的列表),一个列表应包含可用于在 JSP 中创建复选框的复选框的所有值,另一个列表应包含仅那些被选择的值。假设您需要在 jsp 中拥有类似的内容才能执行此操作
One easy solution is to create two list (
arrayList
or any collection based list ) one should contain all the values of check-box which can be used to create check-boxes in your JSP, other list should contain only those values which are selected. Say you need to have something likeIn you jsp all you need to do this