Class UISelectOne
- All Implemented Interfaces:
EditableValueHolder, PartialStateHolder, StateHolder, TransientStateHolder, ValueHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener
- Direct Known Subclasses:
HtmlSelectOneListbox, HtmlSelectOneMenu, HtmlSelectOneRadio
UISelectOne is a UIComponent that represents the user's choice
of zero or one items from among a discrete set of available options. The user can modify the selected value.
Optionally, the component can be preconfigured with a currently selected item, by storing it as the
value property of the component.
This component is generally rendered as a select box or a group of radio buttons.
By default, the rendererType property is set to "jakarta.faces.Menu". This value can be
changed by calling the setRendererType() method.
-
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 TypeMethodDescriptionReturn the identifier of the component family to which this component belongs.getGroup()Returns the name of the radio button group.voidprocessValidators(FacesContext context) IfgetGroup()is set, andUIInput.getSubmittedValue()is empty, and at least one other component having the same group within aUIFormparent has a non-emptyUIInput.getSubmittedValue()or returnstrueonUIInput.isLocalValueSet()or returnsfalseonUIInput.isValid(), then skip validation for current component, else perform standard superclass processing bysuper.processValidators(context).voidSets the name of the radio button group.protected voidvalidateValue(FacesContext context, Object value) In addition to the standard validation behavior inherited fromUIInput, ensure that any specified value is equal to one of the available options.Methods inherited from class UIInput
addValidator, addValueChangeListener, clearInitialState, compareValues, decode, getConvertedValue, getConverterMessage, getRequiredMessage, getSubmittedValue, getValidatorMessage, getValidators, getValue, getValueChangeListeners, isEmpty, isImmediate, isLocalValueSet, isRequired, isValid, markInitialState, processDecodes, processUpdates, removeValidator, removeValueChangeListener, resetValue, restoreState, saveState, setConverterMessage, setImmediate, setLocalValueSet, setRequired, setRequiredMessage, setSubmittedValue, 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.protected booleancompareValues(Object previous, Object value) Returntrueif the new value is different from the previous value.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.Return the submittedValue value of thisUIInputcomponent.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().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.voidsetSubmittedValue(Object submittedValue) Set the submittedValue value of thisUIInputcomponent.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, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, 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.jakarta.el.ValueExpressiongetValueExpression(String name) Return theValueExpressionused to calculate the value for the specified attribute or property name, if any.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.voidsetValueExpression(String name, jakarta.el.ValueExpression binding) Set theValueExpressionused to calculate the value for the specified attribute or property name, if any.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
-
UISelectOne
public UISelectOne()Create a new
UISelectOneinstance 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 -
getGroup
Returns the name of the radio button group.
Radio button components having the same group within a
UIFormparent will uncheck all others when being checked. If thevalueattribute is absent then the one from first component of the group will be used. If theUISelectItemchild is absent then the one from first component of the group will be used.- Returns:
- The name of the radio button group.
- Since:
- 2.3
-
setGroup
Sets the name of the radio button group.
- Parameters:
group- The name of the radio button group.- Since:
- 2.3
-
processValidators
If
getGroup()is set, andUIInput.getSubmittedValue()is empty, and at least one other component having the same group within aUIFormparent has a non-emptyUIInput.getSubmittedValue()or returnstrueonUIInput.isLocalValueSet()or returnsfalseonUIInput.isValid(), then skip validation for current component, else perform standard superclass processing bysuper.processValidators(context).- Overrides:
processValidatorsin classUIInput- Parameters:
context-FacesContextfor the request we are processing- See Also:
-
validateValue
In addition to the standard validation behavior inherited from
UIInput, ensure that any specified value is 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.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
-