Top Description Inners Fields Constructors Methods
jakarta.faces.component

public Class UIForm

extends UIComponentBase
implements NamingContainer, UniqueIdVendor
Class Inheritance
All Implemented Interfaces
jakarta.faces.component.UniqueIdVendor, jakarta.faces.component.NamingContainer
Known Direct Subclasses
jakarta.faces.component.html.HtmlForm
Static Imports
com.sun.faces.util.Util.coalesce, jakarta.faces.component.UIViewRoot.UNIQUE_ID_PREFIX, jakarta.faces.component.visit.VisitResult.COMPLETE

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
UIForm.PropertyKeys

Properties that are tracked by state saving.

Field Summary

Modifier and TypeField and Description
public static final String
COMPONENT_FAMILY

The standard component family for this component.

public static final String
COMPONENT_TYPE

The standard component type for this component.

Constructor Summary

AccessConstructor and Description
public
UIForm()

Create a new UIForm instance with default property values.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

a unique-id in this component-container
createUniqueId
(FacesContext
FacesContext
context
,
String
an optional seed value - e.g. based on the position of the component in the VDL-template
seed
)

Implements jakarta.faces.component.UniqueIdVendor.createUniqueId.

Generate an identifier for a component.

public String
getContainerClientId(FacesContext
the Faces context.
context
)

Overrides jakarta.faces.component.UIComponent.getContainerClientId.

Override the UIComponent#getContainerClientId to allow users to disable this form from prepending its clientId to its descendent's clientIds depending on the value of this form's isPrependId property.

public String
getFamily()

Implements abstract jakarta.faces.component.UIComponent.getFamily.

Return the identifier of the component family to which this component belongs.

private Integer
public boolean
invokeOnComponent(FacesContext
the FacesContext for the current request
context
,
String
the client identifier of the component to be passed to the argument callback.
clientId
,
ContextCallback
an implementation of the Callback interface.
callback
)

Overrides jakarta.faces.component.UIComponentBase.invokeOnComponent.

Starting at this component in the View hierarchy, search for a component with a clientId equal to the argument clientId and, if found, call the ContextCallback#invokeContextCallback method on the argument callback, passing the current FacesContext and the found component as arguments.

public boolean

Returns:

true if it is, false otherwise.
isPrependId
()

Is the id prepended.

public boolean

Returns:

true if the form was submitted, false otherwise.
isSubmitted
()

Returns the current value of the submitted property.

public void
processDecodes(FacesContext
FacesContext for the request we are processing
context
)

Overrides jakarta.faces.component.UIComponentBase.processDecodes.

Override UIComponent#processDecodes to ensure that the form is decoded before its children.

public void
processUpdates(FacesContext
FacesContext for the request we are processing
context
)

Overrides jakarta.faces.component.UIComponentBase.processUpdates.

Override UIComponent#processUpdates to ensure that the children of this UIForm instance are only processed if isSubmitted returns true.

public void
processValidators(FacesContext
FacesContext for the request we are processing
context
)

Overrides jakarta.faces.component.UIComponentBase.processValidators.

Override UIComponent#processValidators to ensure that the children of this UIForm instance are only processed if isSubmitted returns true.

private void
public void
setPrependId(boolean
true if it is, false otherwise.
prependId
)

Set whether the id should be prepended.

public void
setSubmitted(boolean
the new value of the submitted flag.
submitted
)

If this UIForm instance (as opposed to other forms in the page) is experiencing a submit during this request processing lifecycle, this method must be called, with true as the argument, during the UIComponent#decode for this UIForm instance.

public boolean
visitTree(VisitContext
the VisitContext for this visit
context
,
VisitCallback
the VisitCallback instance whose visit method will be called for each node visited.
callback
)

Overrides jakarta.faces.component.UIComponent.visitTree.

Perform a tree visit starting at this node in the tree.

Inherited from jakarta.faces.component.UIComponentBase:
addClientBehavioraddFacesListenerbroadcastclearInitialStatedecodeencodeBeginencodeChildrenencodeEndfindComponentgetAttributesgetChildCountgetChildrengetClientBehaviorsgetClientIdgetDefaultEventNamegetDescriptorMapgetEventNamesgetFacesContextgetFacesListenersgetFacetgetFacetCountgetFacetsgetFacetsAndChildrengetIdgetListenersForEventClassgetParentgetPassThroughAttributesgetRenderergetRendererTypegetRendersChildrenisRenderedisTransientmarkInitialStateprocessRestoreStateprocessSaveStatequeueEventremoveFacesListenerrestoreAttachedStaterestoreStatesaveAttachedStatesaveStatesetIdsetParentsetRenderedsetRendererTypesetTransientsubscribeToEventunsubscribeFromEvent

Field Detail

COMPONENT_FAMILYback to summary
public static final String COMPONENT_FAMILY

The standard component family for this component.

COMPONENT_TYPEback to summary
public static final String COMPONENT_TYPE

The standard component type for this component.

Constructor Detail

UIFormback to summary
public UIForm()

Create a new UIForm instance with default property values.

Method Detail

createUniqueIdback to summary
public String createUniqueId(FacesContext context, String seed)

Implements jakarta.faces.component.UniqueIdVendor.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 prependId property has the value false, this method must call createUniqueId on the next ancestor UniqueIdVendor.

Parameters
context:FacesContext

FacesContext

seed:String

an optional seed value - e.g. based on the position of the component in the VDL-template

Returns:String

a unique-id in this component-container

Annotations
@Override
getContainerClientIdback to summary
public String getContainerClientId(FacesContext context)

Overrides jakarta.faces.component.UIComponent.getContainerClientId.

Override the UIComponent#getContainerClientId to allow users to disable this form from prepending its clientId to its descendent's clientIds depending on the value of this form's isPrependId property.

Parameters
context:FacesContext

Doc from jakarta.faces.component.UIComponent.getContainerClientId.

the Faces context.

Returns:String

Doc from jakarta.faces.component.UIComponent.getContainerClientId.

the container client id.

Annotations
@Override
getFamilyback to summary
public String getFamily()

Implements abstract jakarta.faces.component.UIComponent.getFamily.

Doc from jakarta.faces.component.UIComponent.getFamily.

Return the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the rendererType property, may be used to select the appropriate Renderer for this component instance. Note this method should NOT return null

Returns:String

the component family (not null).

Annotations
@Override
getLastIdback to summary
private Integer getLastId()
invokeOnComponentback to summary
public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback) throws FacesException

Overrides jakarta.faces.component.UIComponentBase.invokeOnComponent.

Doc from jakarta.faces.component.UIComponentBase.invokeOnComponent.

Starting at this component in the View hierarchy, search for a component with a clientId equal to the argument clientId and, if found, call the ContextCallback#invokeContextCallback method on the argument callback, passing the current FacesContext and the found component as arguments. This method is similar to findComponent but it does not support the leading UINamingContainer#getSeparatorChar syntax for searching from the root of the View.

The default implementation will first check if this.getClientId() is equal to the argument clientId. If so, first call pushComponentToEL, then call the ContextCallback#invokeContextCallback method on the argument callback, passing through the FacesContext argument and passing this as the component argument. Then call popComponentFromEL. If an Exception is thrown by the callback, wrap it in a FacesException and re-throw it. Otherwise, return true.

Otherwise, for each component returned by getFacetsAndChildren, call invokeOnComponent() passing the arguments to this method, in order. The first time invokeOnComponent() returns true, abort traversing the rest of the Iterator and return true.

When calling ContextCallback#invokeContextCallback 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 argument clientId. For example, an iterating component such as UIData will need to set its row index to correctly reflect the argument clientId before finding the appropriate child component backed by the correct row. When the callback returns, either normally or by throwing an Exception the 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 getFacetsAndChildren returned true from invokeOnComponent(), return false.

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;
            }
         });
   }

Parameters
context:FacesContext

Doc from jakarta.faces.component.UIComponent.invokeOnComponent.

the FacesContext for the current request

clientId:String

Doc from jakarta.faces.component.UIComponent.invokeOnComponent.

the client identifier of the component to be passed to the argument callback.

callback:ContextCallback

Doc from jakarta.faces.component.UIComponent.invokeOnComponent.

an implementation of the Callback interface.

Returns:boolean

Doc from jakarta.faces.component.UIComponent.invokeOnComponent.

true if the a component with the given clientId is found, the callback method was successfully invoked passing that component as an argument, and no Exception was thrown. Returns false if no component with the given clientId is found.

Annotations
@Override
Exceptions
FacesException:
if the argument Callback throws an Exception, it is wrapped in a FacesException and re-thrown.
See Also
UIComponent#invokeOnComponent
isPrependIdback to summary
public boolean isPrependId()

Is the id prepended.

Returns:boolean

true if it is, false otherwise.

isSubmittedback to summary
public boolean isSubmitted()

Returns the current value of the submitted property. The default value is false. See setSubmitted for details.

This property must be kept as a transient property using the UIComponent#getTransientStateHelper.

Returns:boolean

true if the form was submitted, false otherwise.

processDecodesback to summary
public void processDecodes(FacesContext context)

Overrides jakarta.faces.component.UIComponentBase.processDecodes.

Override UIComponent#processDecodes to ensure that the form is decoded before its children. This is necessary to allow the submitted property to be correctly set.

Parameters
context:FacesContext

Doc from jakarta.faces.component.UIComponent.processDecodes.

FacesContext for the request we are processing

Annotations
@Override
Exceptions
NullPointerException:
if context is null
processUpdatesback to summary
public void processUpdates(FacesContext context)

Overrides jakarta.faces.component.UIComponentBase.processUpdates.

Override UIComponent#processUpdates to ensure that the children of this UIForm instance are only processed if isSubmitted returns true.

Parameters
context:FacesContext

Doc from jakarta.faces.component.UIComponent.processUpdates.

FacesContext for the request we are processing

Annotations
@Override
Exceptions
NullPointerException:
if context is null
processValidatorsback to summary
public void processValidators(FacesContext context)

Overrides jakarta.faces.component.UIComponentBase.processValidators.

Override UIComponent#processValidators to ensure that the children of this UIForm instance are only processed if isSubmitted returns true.

Parameters
context:FacesContext

Doc from jakarta.faces.component.UIComponent.processValidators.

FacesContext for the request we are processing

Annotations
@Override
Exceptions
NullPointerException:
if context is null
See Also
jakarta.faces.event.PreValidateEvent, jakarta.faces.event.PostValidateEvent
setLastIdback to summary
private void setLastId(Integer lastId)
setPrependIdback to summary
public void setPrependId(boolean prependId)

Set whether the id should be prepended.

Parameters
prependId:boolean

true if it is, false otherwise.

setSubmittedback to summary
public void setSubmitted(boolean submitted)

If this UIForm instance (as opposed to other forms in the page) is experiencing a submit during this request processing lifecycle, this method must be called, with true as the argument, during the UIComponent#decode for this UIForm instance. If this UIForm instance is not experiencing a submit, this method must be called, with false as the argument, during the UIComponent#decode for this UIForm instance.

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:boolean

the new value of the submitted flag.

visitTreeback to summary
public boolean visitTree(VisitContext context, VisitCallback callback)

Overrides jakarta.faces.component.UIComponent.visitTree.

Doc from jakarta.faces.component.UIComponent.visitTree.

Perform a tree visit starting at this node in the tree.

UIComponent.visitTree() implementations do not invoke the VisitCallback directly, but instead call VisitContext#invokeVisitCallback to invoke the callback. This allows VisitContext implementations to provide optimized tree traversals, for example by only calling the VisitCallback for a subset of components.

UIComponent.visitTree() implementations must call UIComponent.pushComponentToEL() before performing the visit and UIComponent.popComponentFromEL() after the visit.

Parameters
context:VisitContext

the VisitContext for this visit

callback:VisitCallback

the VisitCallback instance whose visit method will be called for each node visited.

Returns:boolean

component implementations may return true to 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.

Annotations
@Override
See Also
UIComponent#visitTree
jakarta.faces.component back to summary

pack-priv final Enum UIForm.PropertyKeys

extends Enum<UIForm.PropertyKeys>
Class Inheritance

Properties that are tracked by state saving.

Field Summary

Modifier and TypeField and Description
public static final UIForm.PropertyKeys
public static final UIForm.PropertyKeys
prependId

The prependId flag.

public static final UIForm.PropertyKeys

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static UIForm.PropertyKeys
public static UIForm.PropertyKeys[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

lastIdback to summary
public static final UIForm.PropertyKeys lastId

Last id vended by UIForm#createUniqueId(jakarta.faces.context.FacesContext, String).

prependIdback to summary
public static final UIForm.PropertyKeys prependId

The prependId flag.

submittedback to summary
public static final UIForm.PropertyKeys submitted

Constructor Detail

PropertyKeysback to summary
private PropertyKeys()

Method Detail

valueOfback to summary
public static UIForm.PropertyKeys valueOf(String name)
valuesback to summary
public static UIForm.PropertyKeys[] values()