This has been implemented (at least) in Seam (s:selectItems) and MyFaces
(t:selectItems). Seam implements a more complete version of this control (adds
itemDisabled, itemLabelEscaped) and I'm more familiar with it, so I'll base this
proposal on it, but I believe the behaviour of the two is nearly identical.
I propose the following addition to the value attribute:
- If the collection is genericised with SelectItem or the array has a
componentType of SelectItem, or a Map is used then the current text is used to
define what happens to the value
- If the value is a collection or array, the values are converted to a
Collection of selectItems using the algorithm detailed below
- If the value is of type DataModel, the result of dataModel.getWrappedData() is
passed to this algorithm
The following additional fields are defined on f:selectItems, all of which take
EL. These allow the options specified on <f:selectItem /> to be applied to the
- var - The request-scope attribute (if any) under which the data object for the
current row will be exposed when iterating.
- itemValue - Value to return to the server if this option is selected.
Optional, by default the var object is used. Can reference the var variable.
- itemLabel - the label to be used when rendering the SelectItem. Can reference
the var variable.
- itemDisabled - if true the SelectItem will be rendered disabled. Can reference
the var variable.
- itemDescription - Description of this option, for use in development tools.
Can reference the var variable.
- itemLabelEscaped - if false, characters in the label will not be escaped. Can
reference the var variable.
The following algorithm is used to convert any collection or array to a
For each item in the collection or array, push the object into the request map
under the name given by the var attribute. Create a SelectItem object using the
values of itemValue, itemLabel, itemLabelEscaped, itemDisabled, which may
reference the var object. Each SelectItem created must be added to the returned
Collection<SelectItem>, with ordering preserved. The object pushed into the
request map must be removed after the SelectItem has been removed.