gpt4 book ai didi

jsf-2 - Primefaces selectManyMenu 默认选择

转载 作者:行者123 更新时间:2023-12-01 09:37:14 26 4
gpt4 key购买 nike

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>

最佳答案

你的 <f:selectItems itemValue>是不正确的。它应该代表您想要在 <p:selectManyMenu value> 后面的集合中单独设置的值。 .

应该这样做:

itemValue="#{loc}"

omnifaces.SelectItemsConverter是适合此目的的转换器。 omnifaces.ListConverter仅适用于那些不使用 <f:selectItem(s)> 的组件作为 child ,而是一个“普通的”List作为自己的属性,例如 <p:autoComplete><p:pickList> .

关于jsf-2 - Primefaces selectManyMenu 默认选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com