2
p:selectedManyManu是否允許默認選擇?我一直無法實現這一點。我甚至嘗試過Omnifaces ListConverter和selectItemsConverter,但都沒有成功。任何幫助或指針表示讚賞。當頁面加載時,默認情況下可以選擇多個項目。這裏是我的代碼:Primefaces selectManyMenu默認選擇
POJO:
public class LocationRef implements Serializable{
private integer Seqid;
private String locname;
private String locaddress;
private String phonenumber;
//getters and setters
//tostring
//equals, hashcode
}
後端豆:
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>
就是這樣。將selectManyMenu值設置爲selectItems ItemValue的相同類型(集合)解決了它。謝謝。 – Tandina
不客氣。 – BalusC