2013-07-19 3 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)>을 사용하지 않고 대신 <p:autoComplete><p:pickList>과 같은 자체 특성으로 "일반"List을 사용하는 구성 요소에만 해당됩니다.

+0

그게 전부입니다. selectManyMenu 값을 selectItems ItemValue와 동일한 유형 (컬렉션)으로 설정하면 해결됩니다. 감사. – Tandina

+0

반갑습니다. – BalusC