Java 如何使用实体列表默认选中值struts 2 checkboxlist
我正在尝试使用struts checkboxlist默认检查一些值: CheckBoxListAction.classJava 如何使用实体列表默认选中值struts 2 checkboxlist,java,jsp,struts2,entity,checkboxlist,Java,Jsp,Struts2,Entity,Checkboxlist,我正在尝试使用struts checkboxlist默认检查一些值: CheckBoxListAction.class public class CheckBoxListAction extends ActionSupport{ private List<Categories> listCategories; private List<Categories> categories; public void s
public class CheckBoxListAction extends ActionSupport{
private List<Categories> listCategories;
private List<Categories> categories;
public void setListCategories(List<Categories> listCategories) {
this.listCategories = listCategories;
}
public List<Categories> getListCategories() {
listCategories = new ArrayList<>();
listCategories.add(new Categories(1, "AAA"));
listCategories.add(new Categories(2, "BBB"));
listCategories.add(new Categories(3, "CCC"));
listCategories.add(new Categories(4, "DDD"));
return listCategories;
}
public List<Categories> getCategories() {
return categories;
}
public void setCategories(List<Categories> categories) {
this.categories = categories;
}
public List<Categories> getDefaultCategories(){
List<Categories> vList = new ArrayList<>();
vList.add(new Categories(1, "AAA"));
vList.add(new Categories(2, "BBB"));
return vList;
}
}
我期望:[X]AAA[X]BBB[]CCC[]DDD
,但“AAA”和“BBB”未作为默认值进行检查
我遵循了本教程:并查看了stackoverflow中的一些常见问题,但无法找出问题所在
非常感谢您的帮助,英语不好也很抱歉。很抱歉大家打扰您 在多次尝试之后,解决方案位于值端,而不是实体
public List<Integer> getDefaultCategories(){
List<Integer> vInt = new ArrayList<>();
vInt.add(1);
vInt.add(2);
return vInt;
}
公共列表getDefaultCategories(){
List vInt=new ArrayList();
添加第(1)款;
添加(2)个葡萄酒;
返回葡萄酒;
}
谢谢你的帮助。很抱歉大家打扰了你 在多次尝试之后,解决方案位于值端,而不是实体
public List<Integer> getDefaultCategories(){
List<Integer> vInt = new ArrayList<>();
vInt.add(1);
vInt.add(2);
return vInt;
}
公共列表getDefaultCategories(){
List vInt=new ArrayList();
添加第(1)款;
添加(2)个葡萄酒;
返回葡萄酒;
}
谢谢您的帮助。您检查了答案吗?是的,我检查了,但没有结果。您检查了答案吗?是的,我检查了,但没有结果
<input type="checkbox" name="categories" value="1" id="checkboxlist_categories-1"/>
<label for="checkboxlist_categories-1" class="checkboxLabel">AAA</label>
<input type="checkbox" name="categories" value="2" id="checkboxlist_categories-2"/>
<label for="checkboxlist_categories-2" class="checkboxLabel">BBB</label>
<input type="checkbox" name="categories" value="3" id="checkboxlist_categories-3"/>
<label for="checkboxlist_categories-3" class="checkboxLabel">CCC</label>
<input type="checkbox" name="categories" value="4" id="checkboxlist_categories-4"/>
<label for="checkboxlist_categories-4" class="checkboxLabel">DDD</label>
<input type="hidden" id="__multiselect_customer-categories-new_categories" name="__multiselect_categories" value="" />
public List<Integer> getDefaultCategories(){
List<Integer> vInt = new ArrayList<>();
vInt.add(1);
vInt.add(2);
return vInt;
}