2013-07-19 88 views
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> 

回答

2

<f:selectItems itemValue>是不對的。它應該代表您想要在<p:selectManyMenu value>後面的集合中單獨設置的相同值。

這應做到:

itemValue="#{loc}" 

omnifaces.SelectItemsConverter是爲目的的權利轉換器。 omnifaces.ListConverter僅適用於那些不使用<f:selectItem(s)>作爲孩子的組件,而是作爲自己的屬性的「普通」List,如<p:autoComplete><p:pickList>

+0

就是這樣。將selectManyMenu值設置爲selectItems ItemValue的相同類型(集合)解決了它。謝謝。 – Tandina

+0

不客氣。 – BalusC