Question

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>
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top