Package org.omnifaces.converter
Class SelectItemsIndexConverter
- java.lang.Object
-
- org.omnifaces.converter.SelectItemsIndexConverter
-
public class SelectItemsIndexConverter extends Object implements Converter<Object>
The
omnifaces.SelectItemsIndexConverteris a variant of theSelectItemsConverterwhich automatically converts based on the position (index) of the selected item in the list instead of theObject.toString()of the selected item.Usage
This converter is available by converter ID
omnifaces.SelectItemsIndexConverter. Just specify it in theconverterattribute of the selection component holding<f:selectItems>.<h:selectOneMenu value="#{bean.selectedItem}" converter="omnifaces.SelectItemsIndexConverter"> <f:selectItems value="#{bean.availableItems}" /> </h:selectOneMenu>Pros and cons as compared to
SelectItemsConverterThis 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:
SelectItemsUtils,SelectItemsCollector
- No need to rely on
-
-
Field Summary
-
Fields inherited from interface jakarta.faces.convert.Converter
DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME
-
-
Constructor Summary
Constructors Constructor Description SelectItemsIndexConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectgetAsObject(FacesContext context, UIComponent component, String submittedValue)StringgetAsString(FacesContext context, UIComponent component, Object modelValue)
-
-
-
Method Detail
-
getAsObject
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue)
- Specified by:
getAsObjectin interfaceConverter<Object>
-
getAsString
public String getAsString(FacesContext context, UIComponent component, Object modelValue)
- Specified by:
getAsStringin interfaceConverter<Object>
-
-