我有一个ArrayList
的自定义对象(ArrayList<Cell> allCells
)和一个sublist
的allList(ArrayList<Cell> checkedCells
)。我想做的是在p:selectManyMenu
中显示 allCells 数组列表,并在菜单中将我的子列表 checkedCells 的对象显示为checked
。
我知道上面的问题应该已经here回答了,但是我认为答案是低质量的,对于这样的基本问题还不清楚,此外,OP还没有使用{我需要使用的{1}}。
单元格类
converter
CellConverter类
public class Cell{
private String value;
// rest member variables getters setters default constructor ommitted
}
selectManyMenu代码
@FacesConverter(forClass= Cell.class, value = "cellConverter")
public class CellConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null || value.isEmpty()) {
return null;
}
else{
CellBean cellBean = (CellBean) context.getViewRoot().getViewMap().get("cellBean");
for(Cell cell : cellBean.getAllCells()){
String s = cell.getValue();
if(s.equals(value)){
return cell;
}
}
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null) {
return "";
}
if (!(value instanceof Cell)) {
throw new ConverterException("sth went wrong");
}
Cell cell = (Cell) value;
return cell.getValue();
}
不幸的是,即使列表在selectmanymenu菜单中正确显示,也不会检查属于<p:selectManyMenu converter="cellConverter" value="#{cellBean.checkedCells}"
var="cell" filter="true" filterMatchMode="contains" showCheckbox="true">
<f:selectItems value="#{cellBean.allCells}"
var="entity" itemLabel="#{entity.value}" itemValue="#{entity}" />
<p:column>
<h:outputText value="#{cell.value}" />
</p:column>
</p:selectManyMenu>
列表的元素
假设checkedCells
列表包含值为checkedCells
的单元格
我希望列表显示如下
但是列表显示如下(即使我调试了`checkedCells变量,并且实际上包含了这个值)
Primefaces版本:7.0
谢谢。