问题描述
p:selectedManyManu是否允许默认选择?我一直无法实现这一点.我什至尝试了Omnifaces ListConverter和selectItemsConverter,但没有成功.任何帮助或指针,不胜感激.页面加载时,默认情况下可以选择多个项目.这是我的代码:
Does p:selectedManyManu allow default selection? I have been unable to implement this. I even tried Omnifaces ListConverter and selectItemsConverter without success. Any help or pointer is appreciated. More than one item could be selected by default when the page loads. here is my code:
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>
后面的集合中单独设置的值相同的值.
Your <f:selectItems itemValue>
is not right. It should represent the same value as you'd like to invididually set in the collection behind <p:selectManyMenu value>
.
这应该做到:
itemValue="#{loc}"
omnifaces.SelectItemsConverter
是用于此目的的正确转换器. omnifaces.ListConverter
仅适用于那些不将<f:selectItem(s)>
用作子代而将普通" List
用作自己的属性的组件,例如<p:autoComplete>
和<p:pickList>
.
The omnifaces.SelectItemsConverter
is the right converter for the purpose. The omnifaces.ListConverter
is only for those components which don't use <f:selectItem(s)>
as child, but instead a "plain" List
as own attribute, such as <p:autoComplete>
and <p:pickList>
.
这篇关于Primefaces selectManyMenu默认选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!