Primefaces selectManyMenu默认选择

3

p:selectedManyManu 是否允许默认选择?我一直无法实现这一点。我甚至尝试了 Omnifaces ListConverter 和 selectItemsConverter,但都没有成功。任何帮助或指针都将不胜感激。页面加载时可以默认选择多个项目。这是我的代码:

POJO:

public class LocationRef implements Serializable{
private integer Seqid;
private String locname;
private String locaddress;
private String phonenumber;

//getters and setters
//tostring
//equals, hashcode

后端bean:

public class SelectionBean implements Serializable {
private List<LocationRef> selectedLocations;
private List<LocationRef> allLocations;

@PostConstruct
public void init() {
    selectedLocations = new ArrayList<LocationRef>();
    allLocations = new ArrayList<LocationRef>();
    selectedLocation = dao.getSelectedLocation(idList);
    allLocation = dao.getAllLocations();
}

public List<LocationRef> getSelectedLocations() {
    return selectedLocations;
}
public List<LocationRef> getAllLocations() {
    return allLocations;
}
public void setAllLocations(List<LocationRef> allLocations) {
    this.allLocations = allLocations;
}
}

XHTML:

<p:selectManyMenu  id="location" value="#{SelectionBean.selectedLocations}" 
               converter="omnifaces.SelectItemsConverter"
               showCheckbox="true" style="width: 220px" 
               >
<f:selectItems value="#{SelectionBean.allLocations}" var="loc" 
               itemValue="#{loc.locationSeqid}"
               itemLabel="#{loc.sitename}"/>       
</p:selectManyMenu>
1个回答

2
您的<f:selectItems itemValue>不正确。它应该表示您想在<p:selectManyMenu value>后面单独设置的相同值。
这应该可以解决问题:
itemValue="#{loc}"
omnifaces.SelectItemsConverter 是正确的转换器。 omnifaces.ListConverter 只适用于那些不使用 <f:selectItem(s)> 作为子元素,而是使用“普通”List作为自己属性的组件,例如 <p:autoComplete><p:pickList>

就是这样。将selectManyMenu的值设置为与selectItems ItemValue相同类型(集合)解决了问题。谢谢。 - Tandina

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接