Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Harry Hunter   on Mar 09 In Java Category.

  
Question Answered By: Chad Bradley   on Mar 09

Set the value property of the SelectItem to the ID of your entity not its instance.

List<SelectItem> listForYourCombo = new ArrayList<SelectItem>
for(YourEntity entity : list) {
SelectItem si = new SelectItem();
si.setLabel(entity.toString());
si.setValue(entity.getId()); // <==== The point is here DO NOT USE si.setValue(entity)
}

The you can bind the value property of selectOneMenu to an Integer represented the selected  item using the ID of your entity in your back bean.

<f:selectOneMenu value="#{yourbackbean.selectedEntityID}" />

if you do not underestand the case, download NetBeans IDE you can find wonderful samples there to work with JSF

Share: