Class UIForm
- All Implemented Interfaces:
NamingContainer, PartialStateHolder, StateHolder, TransientStateHolder, UniqueIdVendor, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener
- Direct Known Subclasses:
HtmlForm
UIForm is a UIComponent that represents an input form to be
presented to the user, and whose child components represent (among other things) the input fields to be included when
the form is submitted.
By default, the rendererType property must be set to "jakarta.faces.Form". This value can
be changed by calling the setRendererType() method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe standard component family for this component.static final StringThe standard component type for this component.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.Fields inherited from interface NamingContainer
SEPARATOR_CHARModifier and TypeFieldDescriptionstatic final charThe default separator character used in component identifiers to demarcate navigation to a child naming container, in caseUINamingContainer.getSeparatorChar(jakarta.faces.context.FacesContext)does not resolve to a valid value. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateUniqueId(FacesContext context, String seed) Generate an identifier for a component.getContainerClientId(FacesContext context) Override theUIComponent.getContainerClientId(FacesContext)to allow users to disable this form from prepending itsclientIdto its descendent'sclientIdsdepending on the value of this form'sisPrependId()property.Return the identifier of the component family to which this component belongs.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.booleanDeprecated, for removal: This API element is subject to removal in a future version.booleanReturns the current value of thesubmittedproperty.voidprocessDecodes(FacesContext context) OverrideUIComponent.processDecodes(FacesContext)to ensure that the form is decoded before its children.voidprocessUpdates(FacesContext context) OverrideUIComponent.processUpdates(FacesContext)to ensure that the children of thisUIForminstance are only processed ifisSubmitted()returnstrue.voidprocessValidators(FacesContext context) OverrideUIComponent.processValidators(FacesContext)to ensure that the children of thisUIForminstance are only processed ifisSubmitted()returnstrue.voidsetPrependId(boolean prependId) Deprecated, for removal: This API element is subject to removal in a future version.This attribute breaks theUIComponent.findComponent(String).voidsetSubmitted(boolean submitted) If thisUIForminstance (as opposed to other forms in the page) is experiencing a submit during this request processing lifecycle, this method must be called, withtrueas the argument, during theUIComponent.decode(FacesContext)for thisUIForminstance.booleanvisitTree(VisitContext context, VisitCallback callback) Perform a tree visit starting at this node in the tree.Methods inherited from class UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, isRendered, isTransient, markInitialState, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, 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.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.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.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.voidFor each of the attached objects on this instance that implementPartialStateHolder, callPartialStateHolder.markInitialState()on the attached object.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).voidrestoreState(FacesContext context, Object state) Perform any processing required to restore the state from the entries in the state Object.static ObjectsaveAttachedState(FacesContext context, Object attachedObject) This method is called byUIComponentsubclasses that want to save one or more attached objects.saveState(FacesContext context) Gets the state of the instance as aSerializableObject.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, getCurrentComponent, getCurrentCompositeComponent, getFacet, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpressionModifier 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.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.
-
Field Details
-
COMPONENT_TYPE
-
COMPONENT_FAMILY
The standard component family for this component.
- See Also:
-
-
Constructor Details
-
UIForm
public UIForm()Create a new
UIForminstance 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- Specified by:
getFamilyin classUIComponent- Returns:
- the component family (not null).
-
isSubmitted
public boolean isSubmitted()Returns the current value of the
submittedproperty. The default value isfalse. SeesetSubmitted(boolean)for details.This property must be kept as a transient property using the
UIComponent.getTransientStateHelper().- Returns:
trueif the form was submitted,falseotherwise.
-
setSubmitted
public void setSubmitted(boolean submitted) If this
UIForminstance (as opposed to other forms in the page) is experiencing a submit during this request processing lifecycle, this method must be called, withtrueas the argument, during theUIComponent.decode(FacesContext)for thisUIForminstance. If thisUIForminstance is not experiencing a submit, this method must be called, withfalseas the argument, during theUIComponent.decode(FacesContext)for thisUIForminstance.The value of a
UIForm's submitted property must not be saved as part of its state.This property must be kept as a transient property using the
UIComponent.getTransientStateHelper().- Parameters:
submitted- the new value of the submitted flag.
-
isPrependId
Deprecated, for removal: This API element is subject to removal in a future version.This attribute breaks theUIComponent.findComponent(String).Is the id prepended.- Returns:
trueif it is,falseotherwise.
-
setPrependId
Deprecated, for removal: This API element is subject to removal in a future version.This attribute breaks theUIComponent.findComponent(String).Set whether the id should be prepended.- Parameters:
prependId-trueif it is,falseotherwise.
-
processDecodes
Override
UIComponent.processDecodes(FacesContext)to ensure that the form is decoded before its children. This is necessary to allow thesubmittedproperty to be correctly set.- Overrides:
processDecodesin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
processValidators
Override
UIComponent.processValidators(FacesContext)to ensure that the children of thisUIForminstance are only processed ifisSubmitted()returnstrue.- Overrides:
processValidatorsin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull- See Also:
-
processUpdates
Override
UIComponent.processUpdates(FacesContext)to ensure that the children of thisUIForminstance are only processed ifisSubmitted()returnstrue.- Overrides:
processUpdatesin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
createUniqueId
Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within this component-container. Optionally, a unique seed value can be supplied by component creators which should be included in the generated unique id.
If the
prependIdproperty has the valuefalse, this method must callcreateUniqueIdon the next ancestorUniqueIdVendor.- Specified by:
createUniqueIdin interfaceUniqueIdVendor- Parameters:
context- FacesContextseed- an optional seed value - e.g. based on the position of the component in the VDL-template- Returns:
- a unique-id in this component-container
-
getContainerClientId
Override the
UIComponent.getContainerClientId(FacesContext)to allow users to disable this form from prepending itsclientIdto its descendent'sclientIdsdepending on the value of this form'sisPrependId()property.- Overrides:
getContainerClientIdin classUIComponent- Parameters:
context- the Faces context.- Returns:
- the container client id.
-
visitTree
Description copied from class:UIComponentPerform a tree visit starting at this node in the tree.
UIComponent.visitTree() implementations do not invoke the
VisitCallbackdirectly, but instead callVisitContext.invokeVisitCallback(UIComponent, VisitCallback)to invoke the callback. This allowsVisitContextimplementations to provide optimized tree traversals, for example by only calling theVisitCallbackfor a subset of components.UIComponent.visitTree() implementations must call UIComponent.pushComponentToEL() before performing the visit and UIComponent.popComponentFromEL() after the visit.
- Overrides:
visitTreein classUIComponent- Parameters:
context- theVisitContextfor this visitcallback- theVisitCallbackinstance whosevisitmethod will be called for each node visited.- Returns:
- component implementations may return
trueto indicate that the tree visit is complete (eg. all components that need to be visited have been visited). This results in the tree visit being short-circuited such that no more components are visited. - See Also:
-
invokeOnComponent
public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback) throws FacesException Description copied from class:UIComponentBaseStarting at this component in the View hierarchy, search for a component with a
clientIdequal to the argumentclientIdand, if found, call theContextCallback.invokeContextCallback(FacesContext, UIComponent)method on the argumentcallback, passing the currentFacesContextand the found component as arguments. This method is similar toUIComponent.findComponent(String)but it does not support the leadingUINamingContainer.getSeparatorChar(FacesContext)syntax for searching from the root of the View.The default implementation will first check if
this.getClientId()is equal to the argumentclientId. If so, first callUIComponent.pushComponentToEL(FacesContext, UIComponent), then call theContextCallback.invokeContextCallback(FacesContext, UIComponent)method on the argument callback, passing through theFacesContextargument and passing this as the component argument. Then callUIComponent.popComponentFromEL(FacesContext). If anExceptionis thrown by the callback, wrap it in aFacesExceptionand re-throw it. Otherwise, returntrue.Otherwise, for each component returned by
UIComponent.getFacetsAndChildren(), callinvokeOnComponent()passing the arguments to this method, in order. The first timeinvokeOnComponent()returns true, abort traversing the rest of theIteratorand returntrue.When calling
ContextCallback.invokeContextCallback(FacesContext, UIComponent)the implementation of this method must guarantee that the state of the component passed to the callback correctly reflects the component's position in the View hierarchy with respect to any state found in the argumentclientId. For example, an iterating component such asUIDatawill need to set its row index to correctly reflect the argumentclientIdbefore finding the appropriate child component backed by the correct row. When the callback returns, either normally or by throwing anExceptionthe implementation of this method must restore the state of the view to the way it was before invoking the callback.If none of the elements from
UIComponent.getFacetsAndChildren()returnedtruefrominvokeOnComponent(), returnfalse.Simple usage example to find a component by
clientId.private UIComponent found = null; private void doFind(FacesContext context, String clientId) { context.getViewRoot().invokeOnComponent(context, clientId, new ContextCallback() { public void invokeContextCallback(FacesContext context, UIComponent component) { found = component; } }); }- Overrides:
invokeOnComponentin classUIComponentBase- Parameters:
context- theFacesContextfor the current requestclientId- the client identifier of the component to be passed to the argument callback.callback- an implementation of the Callback interface.- Returns:
trueif the a component with the givenclientIdis found, the callback method was successfully invoked passing that component as an argument, and no Exception was thrown. Returnsfalseif no component with the givenclientIdis found.- Throws:
FacesException- if the argument Callback throws an Exception, it is wrapped in aFacesExceptionand re-thrown.- See Also:
-
UIComponent.findComponent(String).