从数据库重新填充struts2复选框列表数据 [英] Re-populate struts2 checkboxlist data from database
问题描述
我有一个复选框,如
<s:checkbox name="modProcessVO.byWeeklyCal" id="week">Days of the Week</s:checkbox>
和另一个复选框列表
<s:checkboxlist list="{''Mon'',''Tue'',''Wed'',''Thur'',''Fri'',''Sat'',''Sun''}" name="modProcessVO.weeklyCal" id="days" />
.当我选中复选框时,其值将存储为"true",否则为"false".如果它是"true",那么只有我从复选框列表中保存选中的数据列表.因此,当我想修改数据时,需要将其作为检查从DB重新填充到checkboxlist中.我尝试从行动类中的db中获取一个名为"wordList"的字符串列表,并用jsp编写,如
. When I check the checkbox it''s value will store as ''true'' otherwise ''false'' in database. If it is ''true'' then only I''m saving the checked list of data from the checkboxlist. So when I want to modify the data I need to re-populate it back from DB to checkboxlist as checks . I tried by taking the days from db in action class in a list of string called ''wordList'' and written in jsp like
<s:checkboxlist list="{''Mon'',''Tue'',''Wed'',''Thur'',''Fri'',''Sat'',''Sun''}" name="modProcessVO.weeklyCal" value="%{wordList}" id="days" />
.但是要说如果该列表中有5个值,则只有第一个重新填充到复选框列表中(例如:wordList包含"Sun","Mon"和"Tue",只有"Sun"显示为选中状态) ).请帮助.谢谢
. But say if 5 values are in that list only 1st one is repopulating to checkboxlist (for eg: wordList contains ''Sun'', ''Mon'' & ''Tue'', only ''Sun'' showing as checked). Pls help. Thanks
推荐答案
我解决了这个问题.我会在这里给出我的代码:)
I solved that problem. I''ll give my code here :)
public class ScheduleAction extends ActionSupport {
private String checkListData;
private List<string> wordList;
public String modifySchedule() {
checkListData = modProcessVO.getCalWeek(); // retrieving checked items from database
String regex=",";
String[] test=checkListData.split(regex);
wordList = new ArrayList<string>();
for(String str : test)
{
wordList.add(str.trim());
}
return SUCCESS;
}
//getters and setters of variables
}
</string></string>
在jsp中,我给像
In jsp I''m giving like
<s:checkboxlist list="{''Mon'',''Tue'',''Wed'',''Thur'',''Fri'',''Sat'',''Sun''}" name="modProcessVO.weeklyCal" id="days" value="wordList" xmlns:s="#unknown" />
这篇关于从数据库重新填充struts2复选框列表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!