如何在Primefaces选项列表中预填充目标?
我使用以下代码初始化DualListModel
:
List<Dimension> dimensionsSource = new ArrayList<Dimension>();
List<Dimension> dimensionsTarget = new ArrayList<Dimension>();
Dimension dimension = new Dimension("Year", "year", "name");
dimensionsSource.add(dimension);
dimension = new Dimension("Quarter", "quarter", "id");
dimensionsSource.add(dimension);
dimension = new Dimension("Month", "month", "id");
dimensionsTarget.add(dimension);
dimensions = new DualListModel<Dimension>(dimensionsSource, dimensionsTarget);
当PickList
显示在屏幕上时,它有&#34;月&#34;在目标列表中,但是当我提交数据时getTarget()
返回一个空列表。
答案 0 :(得分:0)
我解决了这个问题!原因是错误的转换器:
@FacesConverter(value = "dimensionsConverter")
public class DimensionsConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
@SuppressWarnings("unchecked")
DualListModel<Dimension> value = (DualListModel<Dimension>)((PickList) uiComponent).getValue();
List<Dimension> source = value.getSource();
for (Dimension dimension : source) {
if(s.equals(dimension.getTableAndOrderColumn())){
return dimension;
}
}
return null;
}
@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
return ((Dimension)o).getTableAndOrderColumn();
}
转换器试图找到一个&#34;月&#34;在源列表中,而月份在目标列表中:) 对你所有人来说都是好的!