Primefaces selectManyMenu default selection

喜你入骨 提交于 2019-12-12 17:29:14

问题


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

}

Backend 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:


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>.

This should do it:

itemValue="#{loc}"

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>.



来源:https://stackoverflow.com/questions/17753542/primefaces-selectmanymenu-default-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!