I am trying to use an converter for custom objects, that are used in a primefaces' selectCheckboxMenu
.
This is the JSF part:
<p:outputLabel value="#{msg.cars}: " for="cars" />
<p:selectCheckboxMenu id="cars"
value="#{controller.selected.cars}"
converter="carConverter" label="#{msg.cars}"
filter="true" filterMatchMode="startsWith"
panelStyle="width:200px">
<f:selectItems
value="#{controller.available.cars}" />
<f:converter converterId="carConverter" />
</p:selectCheckboxMenu>
And this is my converter:
@FacesConverter("carConverter")
public class CarConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String newValue) {
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
if (object == null) {
return "";
}
if (object instanceof Car) {
Car car = (Car) object;
String name = car.getName();
return name;
} else {
throw new ConverterException(new FacesMessage(object + " is not a valid car"));
}
}
}
getAsString()
returns the correct String. But the selectCheckboxMenu
still lists the objects and not the Strings.
Am I missing something?