public class SelectItemsConverter extends Object implements Converter
This class can be used as-is provided the Object has a toString
method that uniquely identifies it and which
makes sense as an identifier. Since this is not the typical case for toString
, users are assumed to override
the getAsString
method and provide an implementation that converts an object to its string representation.
This getAsObject
method will then be used to automatically do the reverse mapping.
This converter is available by converter ID omnifaces.SelectItemsConverter
. Basic usage example:
<h:selectOneMenu value="#{bean.selectedEntity}" converter="omnifaces.SelectItemsConverter"> <f:selectItems value="#{bean.availableEntities}" var="entity" itemValue="#{entity}" itemLabel="#{entity.someProperty}" /> </h:selectOneMenu>
When extending this converter to override getAsString()
to return something simpler, such as the entity
ID by return String.valueOf(((Entity) value).getId());
, you only have to change the converter
attribute in the above example to refer the extended converter instead.
Constructor and Description |
---|
SelectItemsConverter() |
Modifier and Type | Method and Description |
---|---|
Object |
getAsObject(FacesContext context,
UIComponent component,
String value) |
String |
getAsString(FacesContext context,
UIComponent component,
Object value) |
public Object getAsObject(FacesContext context, UIComponent component, String value)
getAsObject
in interface Converter
public String getAsString(FacesContext context, UIComponent component, Object value)
getAsString
in interface Converter