我试图实现一个调色板。我尝试设置默认的选定列表,但它是空的。
myLists:
// here I get a Set of the categorys which are already in that group
Set<Category> selectedCategorysSet = new HashSet<Category>();
selectedCategorysSet = group.getCategorys();
// here I get all categorys exists
List<Category> listCategory = new ArrayList<Category>();
listCategory = catDao.getAll(Category.class);
List<Category> selectedCats = new ArrayList<Category>();
List<Category> tmpList = new ArrayList<Category>();
// the palette doesnt accept an Set so I added the set to a List
selectedCats.addAll(selectedCategorysSet);
// here I delete every Category from the whole List which is already selected (stored in a temporary list)
for(Category catList:listCategory){
for(Category cat:selectedCategorysSet){
if(cat.getCategoryId() == catList.getCategoryId()){
tmpList.add(catList);
}
}
}
listCategory.removeAll(tmpList);
/*
two multiple select boxes which switches items between each other
*/
IChoiceRenderer<Category> renderer = new ChoiceRenderer<Category>("title","categoryId");
final Palette<Category> palette = new Palette<Category>("palette",
new ListModel<Category>(selectedCats),
new CollectionModel<Category>(listCategory),
renderer, 10, false);
我已经调试了该代码,它可以工作,但我选择的值是空的。
以下是调试变量的图片:
但所选字段仍为空!
我做错了什么?
答案 0 :(得分:3)
您不应删除 every Category from the whole List which is already selected
。
调色板组件必须在代码中存储choicesModel
的整个值列表,listCategory
。
因此,只需从您的实现中删除以下代码:
for(Category catList:listCategory){
for(Category cat:selectedCategorysSet){
if(cat.getCategoryId() == catList.getCategoryId()){
tmpList.add(catList);
}
}
}
listCategory.removeAll(tmpList);