Class ComponentUtils
java.lang.Object
com.webmethods.caf.faces.component.util.ComponentUtils
Component utility functions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Shadow node structure; used to cache the list of descendants at each depth (relative to the UIComponent) for a UIComponent. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
applyAnnotations
(FacesContext context, UIComponent component, boolean deep) Apply annotations that are on the component or renderer classes.static void
baseValidateValue
(FacesContext context, UIInput input, Object value) Base UIInput validation.protected static void
buildShadowComponentMap
(Map<UIComponent, ComponentUtils.ShadowComponentNode> map, UIComponent component, List<ComponentUtils.ShadowComponentNode> ancestors) Builds the shadow component map for the specified component, recursively.static void
clearShadowComponentMap
(FacesContext context, UIComponent component) Clears the cached shadow component map.static void
Clear the submitted values for all the editable value holder controls in the form.static void
copyAttributes
(UIComponent source, UIComponent destination) Copy all the attributes from the source component to the destination componentstatic UIComponent
copyComponent
(FacesContext context, UIComponent sourceComponent) Makes a (deep) copy of a UIComponentstatic String
createAbsoluteIdReference
(UIComponent uiComponent) Creates an absolute component id reference.static String
createAbsoluteIdReference
(FacesContext context, UIComponent source, String relativeId) Creates an absolute component id reference to a component given the specified starting point and control id reference.static String
createClientId
(FacesContext context, UIComponent source, String reference) Creates a client-side id given the specified starting point and control id reference.createClientIdsList
(FacesContext context, UIComponent source, String references) Creates a list of client-side ids given the specified starting point and comma-separated-list of control id references.static UIComponent
findComponent
(FacesContext context, UIComponent source, String reference) Finds a component given the specified starting point and control id reference.protected static UIComponent
findComponentInSiblingSubtreeById
(FacesContext context, UIComponent source, String id) Find least deep component in siblings' subtrees with specified id.protected static UIComponent
findComponentInSubtreeById
(FacesContext context, UIComponent source, String id) Find least deep component in subtree with specified id.static UICommand
findDefaultCommand
(FacesContext context, UIComponent component) Finds the default command for the specified subtree.protected static UICommand
findFirstCommand
(FacesContext context, UIComponent component) Finds the first command for the specified subtree.static List<IScopedVariableComponent>
Find any scoped variable components that are ancestors of the specified controlstatic UIComponent
getCurrentViewFragment
(FacesContext context) Deprecated.static UIComponent
Deprecated.(since 9.10) This is no longer used by the partial/ajax response renderingstatic UIForm
getForm
(FacesContext context, UIComponent component) Finds the form containing the specified component.static String
getFullyQualifiedComponentId
(UIComponent uiComponent) Deprecated.usecreateAbsoluteIdReference(UIComponent)
Returns the fully qualified server-side component id.static Object
getLabel
(FacesContext context, UIComponent component) Return the label of the component or the clientId if no label is supplied.static PageFlowScopeStorage
getPageFlowStorage
(FacesContext facesContext) Gets the active page flow storage objectstatic Object
getPropertyOrBindingValue
(FacesContext context, UIComponent component, String name, Object specifiedValue, Object defaultValue) Gets property value using specified value, theValueExpression
for the specified name, or the default value.protected static Map<UIComponent,
ComponentUtils.ShadowComponentNode> getShadowComponentMap
(FacesContext context, UIComponent component) Gets the cached shadow map, building it if uninitialized.protected static ComponentUtils.ShadowComponentNode
getShadowComponentNode
(FacesContext context, UIComponent component) Gets the shadow node for the specified component from the cached shadow map.static Object
getStoredPageBeanValue
(FacesContext facesContext, String variableName) Get the current value of the given variable, if it exists.static UIViewRoot
getViewRootForComponent
(UIComponent component) Finds the ViewRoot containing the specified component.static boolean
isAsyncRequest
(FacesContext context) True if current request is an async request.static boolean
isEmptyValue
(Object value) Returns true if specified value is an empty input value.static void
popScopedVariables
(Map<String, Object> oldVariablesMap) Restore the previous variables back where they came from when the scoped variables were pushed.pushScopedVariables
(List<IScopedVariableComponent> components) Push the given variables into scopestatic void
renderComponent
(FacesContext ctx, UIComponent component) Render the specified sub-tree to the current response-writer.static void
renderComponent
(FacesContext context, UIComponent component, ResponseWriter writer) Render the specified sub-tree to the specified response-writer.static String
renderComponentHTML
(FacesContext ctx, UIComponent component) Render the specified component as html to a buffer and return its content.static String
renderComponentText
(FacesContext ctx, UIComponent component) Render the specified component to a buffer and extract its plain-text content.static void
reparentChildren
(UIComponent source, UIComponent destination) Moves all the children of the source component to the destination component.static void
replaceFormsWithDisjointForms
(UIComponent component) Recursively replaces any forms in the subtree with disjoint forms.static DisjointForm
replaceWithDisjointForm
(UIComponent original, UIComponent replacement) Replaces the specified original component with a DisjointForm, moving the specified replacement component's children into the DisjointForm.static UINamingContainer
replaceWithNamingContainer
(UIComponent original, UIComponent replacement) Replaces the specified original component with a UINamingContainer, moving the specified replacement component's children into the UINamingContainer.static boolean
setBindingValue
(FacesContext context, UIComponent component, String name, Object value) Sets theValueExpression
for the specified name, if possible.static boolean
setBindingValueWithErrorMessage
(FacesContext context, UIComponent component, String name, Object value) static void
setCurrentViewFragment
(FacesContext context, UIComponent component) Sets current view fragment.static void
setStoredPageBeanValue
(FacesContext facesContext, String variableName, Object newValue) Replaces the current value of the given variable.static void
stripForms
(UIComponent component) Deprecated.usestripForms(UIComponent, boolean)
instead.static void
stripForms
(UIComponent component, boolean skipDisjointForms) Recursively replaces any forms in the subtree with generic UINamingContainers.static MethodBinding
Deprecated.static ValueBinding
Deprecated.
-
Field Details
-
VIEW_FRAGMENT_SET
- See Also:
-
ATTR_SHADOW_COMPONENT_MAP
- See Also:
-
RE_TABLE_ROW_INDEX
-
RE_TABLE_ROW_ID
-
-
Constructor Details
-
ComponentUtils
public ComponentUtils()
-
-
Method Details
-
renderComponent
public static void renderComponent(FacesContext ctx, UIComponent component) throws IOException, FacesException Render the specified sub-tree to the current response-writer.- Parameters:
ctx
- Current context.component
- Component to render.- Throws:
IOException
FacesException
-
renderComponent
public static void renderComponent(FacesContext context, UIComponent component, ResponseWriter writer) throws IOException, FacesException Render the specified sub-tree to the specified response-writer.- Parameters:
context
- Current context.component
- Component to render.writer
- Buffer to which to write.- Throws:
IOException
FacesException
-
renderComponentText
public static String renderComponentText(FacesContext ctx, UIComponent component) throws IOException, FacesException Render the specified component to a buffer and extract its plain-text content.- Parameters:
ctx
- Current context.component
- Component to render.- Throws:
IOException
FacesException
-
renderComponentHTML
public static String renderComponentHTML(FacesContext ctx, UIComponent component) throws IOException, FacesException Render the specified component as html to a buffer and return its content.- Parameters:
ctx
- Current context.component
- Component to render.- Throws:
IOException
FacesException
-
getPropertyOrBindingValue
public static Object getPropertyOrBindingValue(FacesContext context, UIComponent component, String name, Object specifiedValue, Object defaultValue) Gets property value using specified value, theValueExpression
for the specified name, or the default value. This method will return null only if the defaultValue is null.- Parameters:
context
- Current context.component
- Component for which to the value.name
- Property name.specifiedValue
- User-specified value.defaultValue
- Default value.
-
setBindingValue
public static boolean setBindingValue(FacesContext context, UIComponent component, String name, Object value) Sets theValueExpression
for the specified name, if possible.- Parameters:
context
- Current context.component
- Component for which to the value.name
- Property name.value
- Value.- Returns:
- True if binding was set.
-
setBindingValueWithErrorMessage
public static boolean setBindingValueWithErrorMessage(FacesContext context, UIComponent component, String name, Object value) -
baseValidateValue
Base UIInput validation.- Parameters:
context
- Current context.input
- UIInput to validate.value
- Value to validate.
-
isEmptyValue
Returns true if specified value is an empty input value. Empty values are null, empty string (""), empty collection, or empty array. -
getFullyQualifiedComponentId
Deprecated.usecreateAbsoluteIdReference(UIComponent)
Returns the fully qualified server-side component id. This ID can be used to find a component using the UIComponent.findComponent(id) API.- Parameters:
uiComponent
- the component to calculate the id for- Returns:
- the fully qualified component id for the component
-
createAbsoluteIdReference
public static String createAbsoluteIdReference(FacesContext context, UIComponent source, String relativeId) Creates an absolute component id reference to a component given the specified starting point and control id reference.- Parameters:
context
- Current context.source
- Component from which to start search (or null to start from view root).relativeId
- Relative control id reference.- Returns:
- First component found or null if none found.
-
createAbsoluteIdReference
Creates an absolute component id reference. This id can be used to find a component usingUIComponent.findComponent(String)
.- Parameters:
uiComponent
- Component for which to calculate id.- Returns:
- Absolute id reference, or null if component is null.
-
findComponent
Finds a component given the specified starting point and control id reference.- Parameters:
context
- Current context.source
- Component from which to start search (or null to start from view root).reference
- Control id reference.- Returns:
- First component found or null if none found.
-
findComponentInSubtreeById
protected static UIComponent findComponentInSubtreeById(FacesContext context, UIComponent source, String id) Find least deep component in subtree with specified id.- Parameters:
context
- Current context.source
- Root of subtree (search includes source).id
- Component id for which to search.- Returns:
- Least deep component in subtree with specified id (including source), or null if not found.
-
findComponentInSiblingSubtreeById
protected static UIComponent findComponentInSiblingSubtreeById(FacesContext context, UIComponent source, String id) Find least deep component in siblings' subtrees with specified id.- Parameters:
context
- Current context.source
- Component the siblings of which to search (search includes source, but not source's subtree).id
- Component id for which to search.- Returns:
- Least deep component in siblings' subtrees with specified id, or null if not found.
-
clearShadowComponentMap
Clears the cached shadow component map. -
getShadowComponentNode
protected static ComponentUtils.ShadowComponentNode getShadowComponentNode(FacesContext context, UIComponent component) Gets the shadow node for the specified component from the cached shadow map. Rebuilds the shadow map if out-of-date or unitialized. Returns null if shadow node cannot be found for the specified component. -
getShadowComponentMap
protected static Map<UIComponent,ComponentUtils.ShadowComponentNode> getShadowComponentMap(FacesContext context, UIComponent component) Gets the cached shadow map, building it if uninitialized. -
buildShadowComponentMap
protected static void buildShadowComponentMap(Map<UIComponent, ComponentUtils.ShadowComponentNode> map, UIComponent component, List<ComponentUtils.ShadowComponentNode> ancestors) Builds the shadow component map for the specified component, recursively.- Parameters:
map
- Map to build (starts empty).component
- Subtree root.ancestors
- Ancestor stack (starts empty).
-
createClientId
Creates a client-side id given the specified starting point and control id reference.- Parameters:
context
- Current context.source
- Component from which to start search (or null to start from view root).reference
- Control id reference.- Returns:
- Client-side id or null if id could not be constructed.
-
createClientIdsList
public static List<String> createClientIdsList(FacesContext context, UIComponent source, String references) Creates a list of client-side ids given the specified starting point and comma-separated-list of control id references.- Parameters:
context
- Current context.source
- Component from which to start search (or null to start from view root).references
- Comma-separated-list of control id references.- Returns:
- Non-null (possibly empty) list of client-side ids. May return less client-side ids than control-id references.
-
isAsyncRequest
True if current request is an async request. -
getCurrentViewFragment
Deprecated.(since 9.10) UsePartialViewContext.getRenderIds()
to get the list of component IDs that will be rendered by a partial/ajax render response.Returns current view fragment. NOTE: for 9.10 or later, multiple view fragments may be rendered in the same partial/ajax response. In that case this call will only return the first compnent that will be rendered. If you want the full list, then usePartialViewContext.getRenderIds()
to get the full list of component IDs that will be rendered. -
getCurrentViewFragmentReinitialized
Deprecated.(since 9.10) This is no longer used by the partial/ajax response renderingReturns current view fragment, with reinitialized table states. -
setCurrentViewFragment
Sets current view fragment. -
applyAnnotations
Apply annotations that are on the component or renderer classes. NOTE: using this api is discouraged. Instead of creating components directly via "new UIComponent()" calls, it is better to create new component objects via theApplication.createComponent(String)
call where the annotations and other activities are done automatically.- Parameters:
context
- faces contextcomponent
- the component to processdeep
- true to also recursively process the children and facets of the component.
-
copyComponent
public static UIComponent copyComponent(FacesContext context, UIComponent sourceComponent) throws InstantiationException, IllegalAccessException Makes a (deep) copy of a UIComponent- Parameters:
context
- faces contextsourceComponent
- the component to copy- Returns:
- a copy of the source component
- Throws:
InstantiationException
IllegalAccessException
-
findDefaultCommand
Finds the default command for the specified subtree.- Parameters:
context
- Current context.component
- Component subtree to search- Returns:
- Default command component or null. If no command is marked as default, returns the first command in the form.
-
findFirstCommand
Finds the first command for the specified subtree.- Parameters:
context
- Current context.component
- Component subtree to search.- Returns:
- First command component or null.
-
getForm
Finds the form containing the specified component.- Parameters:
context
- Current context.component
- Component whose form to find.- Returns:
- Form or null.
-
getViewRootForComponent
Finds the ViewRoot containing the specified component.- Parameters:
component
- Component whose form to find.- Returns:
- UIViewRoot or null.
-
reparentChildren
Moves all the children of the source component to the destination component.- Parameters:
source
- the source componentdestination
- the destination component
-
copyAttributes
Copy all the attributes from the source component to the destination component- Parameters:
source
- the source componentdestination
- the destination component
-
clearSubmittedValues
Clear the submitted values for all the editable value holder controls in the form. Useful for a command action that would like all the submitted values to be ignored (such as a cancel button).- Parameters:
source
- the control to start from
-
stripForms
Deprecated.usestripForms(UIComponent, boolean)
instead.Recursively replaces any forms in the subtree with generic UINamingContainers. -
stripForms
Recursively replaces any forms in the subtree with generic UINamingContainers.- Since:
- 8.0
-
replaceWithNamingContainer
public static UINamingContainer replaceWithNamingContainer(UIComponent original, UIComponent replacement) Replaces the specified original component with a UINamingContainer, moving the specified replacement component's children into the UINamingContainer. -
replaceFormsWithDisjointForms
Recursively replaces any forms in the subtree with disjoint forms.- Since:
- 8.2 GA
-
replaceWithDisjointForm
Replaces the specified original component with a DisjointForm, moving the specified replacement component's children into the DisjointForm. -
getAncestorScopedVariableComponents
public static List<IScopedVariableComponent> getAncestorScopedVariableComponents(UIComponent control) Find any scoped variable components that are ancestors of the specified control- Parameters:
control
- the leaf control- Returns:
- list of components that are scoped variable components
-
pushScopedVariables
Push the given variables into scope- Parameters:
components
- the list of scoped variable components to process- Returns:
- map of the old values the scoped variables replaced
-
popScopedVariables
Restore the previous variables back where they came from when the scoped variables were pushed.- Parameters:
oldVariablesMap
- the map of old values to restore
-
getStoredPageBeanValue
Get the current value of the given variable, if it exists.- Parameters:
value
- of the variable or null
-
setStoredPageBeanValue
public static void setStoredPageBeanValue(FacesContext facesContext, String variableName, Object newValue) Replaces the current value of the given variable.- Parameters:
facesContext
- the faces contextvariableName
- the name of the variablenewValue
- of the variable or null
-
getPageFlowStorage
Gets the active page flow storage object- Parameters:
facesContext
- the faces context- Returns:
- the page flow storage object
-
getLabel
Return the label of the component or the clientId if no label is supplied.- Parameters:
context
-component
-- Returns:
-
wrapExpression
Deprecated.Convert a ValueExpression to a ValueBinding- Parameters:
ve
- the ValueExpression to wrap- Returns:
- the ValueBinding equivalent
-
wrapExpression
Deprecated.Convert a MethodExpression to a MethodBinding- Parameters:
ve
- the MethodExpression to wrap- Returns:
- the MethodBinding equivalent
-
PartialViewContext.getRenderIds()
to get the list of component IDs that will be rendered by a partial/ajax render response.