java.lang.Object
org.omnifaces.converter.SelectItemsIndexConverter
The omnifaces.SelectItemsIndexConverter is a variant of the SelectItemsConverter which
automatically converts based on the position (index) of the selected item in the list instead of the
Object.toString() of the selected item.
Usage
This converter is available by converter ID omnifaces.SelectItemsIndexConverter. Just specify it in the
converter attribute of the selection component holding <f:selectItems>.
<h:selectOneMenu value="#{bean.selectedItem}" converter="omnifaces.SelectItemsIndexConverter">
<f:selectItems value="#{bean.availableItems}" />
</h:selectOneMenu>
Since OmniFaces 4.5 it's also available by <o:selectItemsIndexConverter> tag.
<h:selectOneMenu value="#{bean.selectedItem}">
<f:selectItems value="#{bean.availableItems}" />
<o:selectItemsIndexConverter />
</h:selectOneMenu>
Pros and cons as compared to SelectItemsConverter
This converter has the following advantages over SelectItemsConverter:
- No need to rely on
Object.toString()method of the object. - No need to extend the
SelectItemsConverterwhenObject.toString()method of the object cannot be used. - No need to expose the object's unique key in its
Object.toString(),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).
- Since:
- 1.3
- Author:
- Patrick Dobler, Bauke Scholtz
- See Also:
-
Field Summary
Fields inherited from interface jakarta.faces.convert.Converter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAsObject(FacesContext context, UIComponent component, String submittedValue) getAsString(FacesContext context, UIComponent component, Object modelValue)
-
Constructor Details
-
SelectItemsIndexConverter
public SelectItemsIndexConverter()
-
-
Method Details
-
getAsObject
- Specified by:
getAsObjectin interfaceConverter<Object>
-
getAsString
- Specified by:
getAsStringin interfaceConverter<Object>
-