The below selectItems is fed from a Session Scoped Map. When the user clicks the Submit button, it is supposed to set a date field in the Request Scoped backing bean and display it on the page.
<h:selectOneMenu value="#{dropDown.selectedDate}">
<f:selectItems value="#{mapValues.dateMap.entrySet()}" var="entry" itemLabel="#{entry.value}" itemValue="#{entry.key}" />
</h:selectOneMenu>
<h:commandButton value="Submit" />
You selected Date #{dropDown.selectedDate}
However, the following conversion error is received:
Conversion Error setting value 'Wed Dec 26 15:09:32 EST 2012' for 'null Converter'.
I'm not sure why this error is received. I attempted setting a javax.faces.DateTime converter on the selectOneMenu tag, but then received an even more cryptic validation error.
Found a post that suggests checking if the equal() method is available, and that the item select is in the dropdown, both of which should be true in this case.
One workaround I can think of is to change my map to be String keyed where dates are saved off as strings. But it seems like an overkill.
Any suggestions on how to get this set up to work?
Backing bean:
@Named
@RequestScoped
public class DropDown {
private Date selectedDate;
public Date getSelectedDate() {
return selectedDate;
}
public void setSelectedDate(Date selectedDate) {
this.selectedDate = selectedDate;
}
}
Map bean:
@Named
@SessionScoped
public class MapValues implements Serializable {
private Map<Date, String> dateMap;
@PostConstruct
public void init() {
dateMap = new LinkedHashMap<Date, String>();
dateMap.put(new Date(), "DATEVALUE1");
}
public Map<Date, String> getDateMap() {
return dateMap;
}
public void setDateMap(Map<Date, String> dateMap) {
this.dateMap = dateMap;
}
}
Thanks!