Class UISelectMany
- All Implemented Interfaces:
EditableValueHolder, PartialStateHolder, StateHolder, TransientStateHolder, ValueHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener
- Direct Known Subclasses:
HtmlSelectManyCheckbox, HtmlSelectManyListbox, HtmlSelectManyMenu
UISelectMany is a UIComponent that
represents the user's choice of a zero or more items from among a discrete set of available options. The user can
modify the selected values. Optionally, the component can be preconfigured with zero or more currently selected
items, by storing them as an array or Collection in the
value property of the component.
This component is generally rendered as a select box or a group of checkboxes.
By default, the rendererType property must be set to "jakarta.faces.Listbox". This value
can be changed by calling the setRendererType() method.
The Renderer for this component must perform the following logic on
getConvertedValue():
Obtain the
Converterusing the following algorithm:If the component has an attached
Converter, use it.If not, look for a
ValueExpressionforvalue(if any). TheValueExpressionmust point to something that is:
An array of primitives (such as
int[]). Look up the registered by-classConverterfor this primitive type.An array of objects (such as
Integer[]orString[]). Look up the registered by-classConverterfor the underlying element type.A
java.util.Collection. Do not convert the values. Instead, convert the provided set of available options to string, exactly as done during render response, and for any match with the submitted values, add the available option as object to the collection.If for any reason a
Convertercannot be found, assume the type to be a String array.
Use the selected Converter (if any) to convert each element in the values array from
the request to the proper type, and store the result of each conversion in a data
structure, called targetForConvertedValues for discussion. Create targetForConvertedValues using
the following algorithm.
-
If the component has a
ValueExpressionforvalueand the type of the expression is an array, let targetForConvertedValues be a new array of the expected type. -
If the component has a
ValueExpressionforvalue, let modelType be the type of the value expression. If modelType is aCollection, do the following to arrive at targetForConvertedValues:-
Ask the component for its attribute under the key "
collectionType", without the quotes. If there is a value for that key, the value must be a String that is a fully qualified Java class name, or aClassobject, or aValueExpressionthat evaluates to a String or aClass. In all cases, the value serves to identify the concrete type of the class that implementsCollection. For discussion, this is called collectionType. Let targetForConvertedValues be a new instance ofCollectionimplemented by the concrete class specified in collectionType. If, collectionType can not be discovered, or an instance ofCollectionimplemented by the concrete class specified in collectionType cannot be created, throw aFacesExceptionwith a correctly localized error message. Note thatFacesExceptionis thrown instead ofConverterExceptionbecause this case would only arise from developer error, rather than end-user error. -
If there is no "
collectionType" attribute, callgetValue()on the component. The result will implementCollection. If the result also implementsCloneable, let targetForConvertedValues be the result of calling itsclone()method, then callingclear()on the clonedCollection. If unable to clone the value for any reason, log a message and proceed to the next step. -
If modelType is a concrete class, let targetForConvertedValues be a new instance of that class. Otherwise, the concrete type for targetForConvertedValues is taken from the following table. All classes are in the
java.utilpackage. All collections must be created with an initial capacity equal to the length of the values array from the request.modelType to targetForConvertedValues mapping If modelType is an instance of then targetForConvertedValues must be an instance of SortedSetTreeSetQueueLinkedListSetHashSetanything else ArrayList
-
-
If the component does not have a
ValueExpressionforvalue, let targetForConvertedValues be an array of typeObject.
Return targetForConvertedValues after populating it with the converted values.
-
Nested Class Summary
Nested classes/interfaces inherited from class UIInput
UIInput.ValidateEmptyFieldsModifier and TypeClassDescriptionstatic enumAllowed values for the initialization parameter named by the "jakarta.faces.VALIDATE_EMPTY_FIELDS" constant. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe standard component family for this component.static final StringThe standard component type for this component.static final StringThe message identifier of theFacesMessageto be created if a value not matching the available options is specified.Fields inherited from class UIInput
ALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUE, CONVERSION_MESSAGE_ID, EMPTY_STRING_AS_NULL_PARAM_NAME, REQUIRED_MESSAGE_ID, UPDATE_MESSAGE_ID, VALIDATE_EMPTY_FIELDS_PARAM_NAMEModifier and TypeFieldDescriptionstatic final StringIf this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, validation must be performed, even when there is no corresponding value for this component in the incoming request.static final StringThe message identifier of theFacesMessageto be created if a conversion error occurs, and neither the page author nor theConverterExceptionprovides a message.static final StringThe name of a context parameter that indicates how empty strings need to be interpreted.static final StringThe message identifier of theFacesMessageto be created if a required check fails.static final StringThe message identifier of theFacesMessageto be created if a model update error occurs, and the thrown exception has no message.static final StringThe name of a context parameter that indicates how empty values should be handled with respect to validation.Fields inherited from class UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEYModifier and TypeFieldDescriptionstatic final StringThis constant enables one to quickly discover the names of the declared composite component attributes that have been given default values by the composite component author.static final StringThe value of this constant is used as the key in the component attribute map, the value for which is ajava.beans.BeanInfoimplementation describing the composite component.static final StringThe value of this constant is used as the key in the composite component BeanDescriptor for aValueExpressionthat evaluates to thecomponent-typeof the composite component rootUIComponentfor this composite component, if one was declared by the composite component author.static final StringThe value of this constant is used as the key in theMapreturned as described inUIComponent.FACETS_KEYfor thePropertyDescriptordescribing the composite component facet.static final StringThe value of this constant is used as the key in the composite component BeanDescriptor for theMap<PropertyDescriptor>that contains meta-information for the declared facets for this composite component.static final StringThe value of this constant is used as the key in the component attributesMapfor theLocationin the view at which this component instance resides. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancompareValues(Object previous, Object value) Returntrueif the new value is different from the previous value.Return the identifier of the component family to which this component belongs.Object[]Return the currently selected values, ornullif there are no currently selected values.Return the submittedValue value of thisUIInputcomponent.jakarta.el.ValueExpressiongetValueExpression(String name) Return anyValueExpressionset forvalueif aValueExpressionforselectedValuesis requested; otherwise, perform the default superclass processing for this method.voidsetSelectedValues(Object[] selectedValues) Set the currently selected values, ornullto indicate that there are no currently selected values.voidsetSubmittedValue(Object submittedValue) Set the submittedValue value of thisUIInputcomponent.voidsetValueExpression(String name, jakarta.el.ValueExpression binding) Store anyValueExpressionspecified forselectedValuesundervalueinstead; otherwise, perform the default superclass processing for this method.protected voidvalidateValue(FacesContext context, Object value) In addition to the standard validation behavior inherited fromUIInput, ensure that any specified values are equal to one of the available options.Methods inherited from class UIInput
addValidator, addValueChangeListener, clearInitialState, decode, getConvertedValue, getConverterMessage, getRequiredMessage, getValidatorMessage, getValidators, getValue, getValueChangeListeners, isEmpty, isImmediate, isLocalValueSet, isRequired, isValid, markInitialState, processDecodes, processUpdates, processValidators, removeValidator, removeValueChangeListener, resetValue, restoreState, saveState, setConverterMessage, setImmediate, setLocalValueSet, setRequired, setRequiredMessage, setValid, setValidatorMessage, setValue, updateModel, validateModifier and TypeMethodDescriptionvoidaddValidator(Validator validator) voidaddValueChangeListener(ValueChangeListener listener) Add a newValueChangeListenerto the set of listeners interested in being notified whenValueChangeEvents occur.voidFor each of the attached objects on this instance that implementPartialStateHolder, callPartialStateHolder.clearInitialState()on the attached object.voiddecode(FacesContext context) Decode any new state of thisUIComponentfrom the request contained in the specifiedFacesContext, and store this state as needed.protected ObjectgetConvertedValue(FacesContext context, Object newSubmittedValue) Convert the submitted value into a "local value" of the appropriate data type, if necessary.If there has been a call toUIInput.setConverterMessage(String)on this instance, return the message.If there has been a call toUIInput.setRequiredMessage(String)on this instance, return the message.If there has been a call toUIInput.setValidatorMessage(String)on this instance, return the message.getValue()If there is a local value, return it, otherwise return the result of callingsuper.getValue().Return the set of registeredValueChangeListeners for thisUIInputinstance.static booleanIs the value denoting an empty value.booleanReturn the "immediate" state for this component.booleanReturn the "local value set" state for this component.booleanReturn the "required field" state for this component.booleanisValid()Return a flag indicating whether the local value of this component is valid (no conversion error has occurred).voidIn addition to the actions taken inUIOutputwhenPartialStateHolder.markInitialState()is called, check if any of the installedValidators are PartialStateHolders and if so, callPartialStateHolder.markInitialState()as appropriate.voidprocessDecodes(FacesContext context) Specialized decode behavior on top of that provided by the superclass.voidprocessUpdates(FacesContext context) In addition to the standardprocessUpdatesbehavior inherited fromUIComponentBase, callsupdateModel().voidprocessValidators(FacesContext context) In addition to the standardprocessValidatorsbehavior inherited fromUIComponentBase, callsvalidate()if theimmediateproperty is false (which is the default); if the component is invalid afterwards, callsFacesContext.renderResponse().voidremoveValidator(Validator validator) voidremoveValueChangeListener(ValueChangeListener listener) Remove an existingValueChangeListener(if any) from the set of listeners interested in being notified whenValueChangeEvents occur.voidConvenience method to reset this component's value to the un-initialized state.voidrestoreState(FacesContext context, Object state) Perform any processing required to restore the state from the entries in the state Object.saveState(FacesContext context) Gets the state of the instance as aSerializableObject.voidsetConverterMessage(String message) Override anyValueExpressionset for the "converterMessage" with the literal argument provided to this method.voidsetImmediate(boolean immediate) Set the "immediate" state for this component.voidsetLocalValueSet(boolean localValueSet) Sets the "local value set" state for this component.voidsetRequired(boolean required) Set the "required field" state for this component.voidsetRequiredMessage(String message) Override anyValueExpressionset for the "requiredMessage" with the literal argument provided to this method.voidsetValid(boolean valid) Set a flag indicating whether the local value of this component is valid (no conversion error has occurred).voidsetValidatorMessage(String message) Override anyValueExpressionset for the "validatorMessage" with the literal argument provided to this method.voidSet the value of thisUIComponent(if any).voidupdateModel(FacesContext context) Perform the following algorithm to update the model data associated with thisUIInput, if any, as appropriate.voidvalidate(FacesContext context) Perform the following algorithm to validate the local value of thisUIInput.Methods inherited from class UIOutput
getConverter, getLocalValue, setConverterModifier and TypeMethodDescriptionReturn theConverter(if any) that is registered for thisUIComponent.Return the local value of thisUIComponent(if any), without evaluating any associatedValueExpression.voidsetConverter(Converter converter) Set theConverter(if any) that is registered for thisUIComponent.Methods inherited from class UIComponentBase
addClientBehavior, addFacesListener, broadcast, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, invokeOnComponent, isRendered, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient, subscribeToEvent, unsubscribeFromEventModifier and TypeMethodDescriptionvoidaddClientBehavior(String eventName, ClientBehavior behavior) This is a default implementation ofClientBehaviorHolder.addClientBehavior(String, ClientBehavior).protected voidaddFacesListener(FacesListener listener) Add the specifiedFacesListenerto the set of listeners registered to receive event notifications from thisUIComponent.voidbroadcast(FacesEvent event) Broadcast the specifiedFacesEventto all registered event listeners who have expressed an interest in events of this type.voidencodeBegin(FacesContext context) If ourrenderedproperty istrue, render the beginning of the current state of thisUIComponentto the response contained in the specifiedFacesContext.voidencodeChildren(FacesContext context) voidencodeEnd(FacesContext context) findComponent(String expression) Search for and return theUIComponentwith anidthat matches the specified search expression (if any), according to the algorithm described below.Return a mutableMaprepresenting the attributes (and properties, see below) associated wth thisUIComponent, keyed by attribute name (which must be a String).intReturn the number of childUIComponents that are associated with thisUIComponent.This is a default implementation ofClientBehaviorHolder.getClientBehaviors().getClientId(FacesContext context) Return a client-side identifier for this component, generating one if necessary.This is a default implementation ofClientBehaviorHolder.getDefaultEventName().This is a default implementation ofClientBehaviorHolder.getEventNames().protected FacesContextConvenience method to return theFacesContextinstance for the current request.protected FacesListener[]getFacesListeners(Class clazz) Return an array of registeredFacesListeners that are instances of the specified class.Convenience method to return the named facet, if it exists, ornullotherwise.intReturn the number of facetUIComponents that are associated with thisUIComponent.Return a mutableMaprepresenting the facetUIComponents associated with thisUIComponent, keyed by facet name (which must be a String).getId()Return the component identifier of thisUIComponent.getListenersForEventClass(Class<? extends SystemEvent> eventClass) Return theSystemEventListenerinstances registered on thisUIComponentinstance that are interested in events of typeeventClass.Return the parentUIComponentof thisUIComponent, if any.getPassThroughAttributes(boolean create) This method has the same specification asUIComponent.getPassThroughAttributes()except that it is allowed to returnnullif and only if the argumentcreateisfalseand no pass through attribute data structure exists for this instance.protected RenderergetRenderer(FacesContext context) Convenience method to return theRendererinstance associated with this component, if any; otherwise, returnnull.Return theRenderertype for thisUIComponent(if any).booleanReturn a flag indicating whether this component is responsible for rendering its child components.booleaninvokeOnComponent(FacesContext context, String clientId, ContextCallback callback) Starting at this component in the View hierarchy, search for a component with aclientIdequal to the argumentclientIdand, if found, call theContextCallback.invokeContextCallback(FacesContext, UIComponent)method on the argumentcallback, passing the currentFacesContextand the found component as arguments.booleanReturntrueif this component (and its children) should be rendered during the Render Response phase of the request processing lifecycle.booleanIf true, the Object implementing this interface must not participate in state saving or restoring.voidprocessRestoreState(FacesContext context, Object state) Perform the component tree processing required by the Restore View phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.processSaveState(FacesContext context) Perform the component tree processing required by the state saving portion of the Render Response phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.voidqueueEvent(FacesEvent event) Queue an event for broadcast at the end of the current request processing lifecycle phase.protected voidremoveFacesListener(FacesListener listener) Remove the specifiedFacesListenerfrom the set of listeners registered to receive event notifications from thisUIComponent.static ObjectrestoreAttachedState(FacesContext context, Object stateObj) This method is called byUIComponentsubclasses that need to restore the objects they saved usingUIComponentBase.saveAttachedState(FacesContext, Object).static ObjectsaveAttachedState(FacesContext context, Object attachedObject) This method is called byUIComponentsubclasses that want to save one or more attached objects.voidSet the component identifier of thisUIComponent(if any).voidsetParent(UIComponent parent) Set the parentUIComponentof thisUIComponent.voidsetRendered(boolean rendered) Set therenderedproperty of thisUIComponent.voidsetRendererType(String rendererType) voidsetTransient(boolean transientFlag) Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.voidsubscribeToEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener) Install the listener instance referenced by argumentcomponentListeneras a listener for events of typeeventClassoriginating from this specific instance ofUIComponent.voidunsubscribeFromEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener) Remove the listener instance referenced by argumentcomponentListeneras a listener for events of typeeventClassoriginating from this specific instance ofUIComponent.Methods inherited from class UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getFacet, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, visitTreeModifier and TypeMethodDescriptionvoidencodeAll(FacesContext context) If this component returnstruefromUIComponent.isRendered(), take the following action.Enable Jakarta Expression Language to access theclientIdof a component.static UIComponentgetCompositeComponentParent(UIComponent component) Finds the nearest composite component parent of the specified component.getContainerClientId(FacesContext context) Allow components that implementNamingContainerto selectively disable prepending their clientId to their descendent's clientIds by breaking the prepending logic into a separately callable method.static UIComponentgetCurrentComponent(FacesContext context) Return theUIComponentinstance that is currently processing.static UIComponentgetCurrentCompositeComponent(FacesContext context) Return the closest ancestor component, relative to the component returned fromUIComponent.getCurrentComponent(FacesContext), that is a composite component, ornullif no such component exists.Convenience method to return the named facet using an enum identifier, if it exists, ornullotherwise.Starting with "this", return the closest component in the ancestry that is aNamingContainerornullif none can be found.This is a convenience method that simply callsUIComponent.getPassThroughAttributes(boolean), passingtrueas the argument.Return aMap<String,String>of theResourceBundlefor this component.protected StateHelperReturn theStateHelperinstance used to help this component implementPartialStateHolder.protected StateHelpergetStateHelper(boolean create) LikeUIComponent.getStateHelper(), but only create a state helper instance if the argumentcreatistrue.Return theTransientStateHelperinstance for thisUIComponentinstance.getTransientStateHelper(boolean create) Return theTransientStateHelperinstance for thisUIComponentinstance.booleanAn implementation ofPartialStateHolder.initialStateMarked(), this method is called by the runtime to test if thePartialStateHolder.markInitialState()method was called.static booleanisCompositeComponent(UIComponent component) Returntrueifcomponentis a composite component, otherwisefalse.booleanisInView()Returntrueif this component is within the view hierarchy otherwisefalseprotected booleanisVisitable(VisitContext context) Returntrueif this component should be visited,falseotherwise.voidpopComponentFromEL(FacesContext context) Pop the currentUIComponentfrom theFacesContextattributes map so that the previousUIComponent, if any, becomes the current component.voidprocessEvent(ComponentSystemEvent event) The default implementation performs the following action.voidpushComponentToEL(FacesContext context, UIComponent component) Push the currentUIComponentthisto theFacesContextattribute map saving the previousUIComponentfor a subsequent call toUIComponent.popComponentFromEL(FacesContext).voidrestoreTransientState(FacesContext context, Object state) For components that need to support the concept of transient state, this method will restore any state saved on a prior call toUIComponent.saveTransientState(FacesContext).saveTransientState(FacesContext context) For components that need to support the concept of transient state, this method will save any state that is known to be transient in nature.voidsetInView(boolean isInView) Updates the status as to whether or not this component is currently within the view hierarchy.booleanvisitTree(VisitContext visitContext, VisitCallback callback) Perform a tree visit starting at this node in the tree.
-
Field Details
-
COMPONENT_TYPE
-
COMPONENT_FAMILY
The standard component family for this component.
- See Also:
-
INVALID_MESSAGE_ID
The message identifier of the
FacesMessageto be created if a value not matching the available options is specified.- See Also:
-
-
Constructor Details
-
UISelectMany
public UISelectMany()Create a new
UISelectManyinstance with default property values.
-
-
Method Details
-
getFamily
Description copied from class:UIComponentReturn the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the
rendererTypeproperty, may be used to select the appropriateRendererfor this component instance. Note this method should NOT returnnull -
getSubmittedValue
Description copied from class:UIInputReturn the submittedValue value of this
UIInputcomponent. This method should only be used by thedecode()andvalidate()method of this component, or its correspondingRenderer.- Specified by:
getSubmittedValuein interfaceEditableValueHolder- Overrides:
getSubmittedValuein classUIInput- Returns:
- the submitted value.
-
setSubmittedValue
Description copied from class:UIInputSet the submittedValue value of this
UIInputcomponent. This method should only be used by thedecode()andvalidate()method of this component, or its correspondingRenderer.- Specified by:
setSubmittedValuein interfaceEditableValueHolder- Overrides:
setSubmittedValuein classUIInput- Parameters:
submittedValue- The new submitted value
-
getSelectedValues
Return the currently selected values, or
nullif there are no currently selected values. This is a typesafe alias forgetValue().- Returns:
- the selected values, or
null.
-
setSelectedValues
Set the currently selected values, or
nullto indicate that there are no currently selected values. This is a typesafe alias forsetValue().- Parameters:
selectedValues- The new selected values (if any)
-
getValueExpression
Return any
ValueExpressionset forvalueif aValueExpressionforselectedValuesis requested; otherwise, perform the default superclass processing for this method.- Overrides:
getValueExpressionin classUIComponent- Parameters:
name- Name of the attribute or property for which to retrieve aValueExpression- Returns:
- the value expression, or
null. - Throws:
NullPointerException- ifnameisnull- Since:
- 1.2
-
setValueExpression
Store any
ValueExpressionspecified forselectedValuesundervalueinstead; otherwise, perform the default superclass processing for this method.- Overrides:
setValueExpressionin classUIComponent- Parameters:
name- Name of the attribute or property for which to set aValueExpressionbinding- TheValueExpressionto set, ornullto remove any currently setValueExpression- Throws:
NullPointerException- ifnameisnull- Since:
- 1.2
-
compareValues
Return
trueif the new value is different from the previous value. Value comparison must not be sensitive to element order.- Overrides:
compareValuesin classUIInput- Parameters:
previous- old value of this componentvalue- new value of this component- Returns:
trueif the new value is different from the previous value,falseotherwise.
-
validateValue
In addition to the standard validation behavior inherited from
UIInput, ensure that any specified values are equal to one of the available options. Before comparing each option, coerce the option value type to the type of this component's value following the Expression Language coercion rules. If the specified value is not equal to any of the options, enqueue an error message and set thevalidproperty tofalse.This method must explicitly support a value argument that is a single value or a value argument that is a
Collectionor Array of values.If
UIInput.isRequired()returnstrue, and the current value is equal to the value of an innerUISelectItemwhoseUISelectItem.isNoSelectionOption()method returnstrue, enqueue an error message and set thevalidproperty tofalse.- Overrides:
validateValuein classUIInput- Parameters:
context- TheFacesContextfor the current requestvalue- The converted value to test for membership.- Throws:
NullPointerException- ifcontextisnull
-