org.omnifaces.converter
Class SelectItemsIndexConverter
java.lang.Object
org.omnifaces.converter.SelectItemsIndexConverter
- All Implemented Interfaces:
- javax.faces.convert.Converter
public class SelectItemsIndexConverter
- extends java.lang.Object
- implements javax.faces.convert.Converter
The SelectItemsIndexConverter
automatically converts between the index of the select
item value and the select item value itself based on its position in the associated select items for the component
for which conversion is taking place.
This converter has the following advantages over SelectItemsConverter
:
- No need to rely on
toString()
method of the object.
- No need to extend the
SelectItemsConverter
when toString()
method of the object cannot be
used.
- No need to expose the object's unique key if that's a problem.
This converter has the following disadvantage over SelectItemsConverter
:
- The "Validation Error: value is not valid" will never occur anymore for the case that the available select items
has incompatibly changed during the postback due to a developer's mistake. The developer should make absolutely sure
that exactly the same list is preserved on postback (e.g. by making it a property of a view scoped or broader scoped
bean).
This converter is available by converter ID omnifaces.SelectItemsIndexConverter
. Basic usage example:
<h:selectOneMenu value="#{bean.selectedEntity}" converter="omnifaces.SelectItemsIndexConverter">
<f:selectItems value="#{bean.availableEntities}" var="entity"
itemValue="#{entity}" itemLabel="#{entity.someProperty}" />
</h:selectOneMenu>
- Since:
- 1.3
- Author:
- Patrick Dobler, Bauke Scholtz
Method Summary |
java.lang.Object |
getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String submittedValue)
|
java.lang.String |
getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.Object modelValue)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SelectItemsIndexConverter
public SelectItemsIndexConverter()
getAsObject
public java.lang.Object getAsObject(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.String submittedValue)
- Specified by:
getAsObject
in interface javax.faces.convert.Converter
getAsString
public java.lang.String getAsString(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component,
java.lang.Object modelValue)
- Specified by:
getAsString
in interface javax.faces.convert.Converter