public class ComponentUtils extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ComponentUtils.ShadowComponentNode
Shadow node structure; used to cache the
list of descendants at each depth (relative to the UIComponent) for a UIComponent.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
ATTR_SHADOW_COMPONENT_MAP |
protected static Pattern |
RE_TABLE_ROW_ID |
protected static Pattern |
RE_TABLE_ROW_INDEX |
protected static String |
VIEW_FRAGMENT_SET |
Constructor and Description |
---|
ComponentUtils() |
Modifier and Type | Method and Description |
---|---|
static 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 |
clearSubmittedValues(UIComponent form)
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 component
|
static UIComponent |
copyComponent(FacesContext context,
UIComponent sourceComponent)
Makes a (deep) copy of a UIComponent
|
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 |
createAbsoluteIdReference(UIComponent uiComponent)
Creates an absolute component 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.
|
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.
|
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> |
getAncestorScopedVariableComponents(UIComponent control)
Find any scoped variable components that are ancestors of the specified control
|
static UIComponent |
getCurrentViewFragment(FacesContext context)
Deprecated.
(since 9.10) Use
PartialViewContext.getRenderIds() to get the list of component IDs that
will be rendered by a partial/ajax render response. |
static UIComponent |
getCurrentViewFragmentReinitialized(FacesContext context)
Deprecated.
(since 9.10) This is no longer used by the partial/ajax response rendering
|
static UIForm |
getForm(FacesContext context,
UIComponent component)
Finds the form containing the specified component.
|
static String |
getFullyQualifiedComponentId(UIComponent uiComponent)
Deprecated.
use
createAbsoluteIdReference(UIComponent)
Returns the fully qualified server-side component id. This ID can be used to
find a component using the UIComponent.findComponent(id) API. |
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 object
|
static Object |
getPropertyOrBindingValue(FacesContext context,
UIComponent component,
String name,
Object specifiedValue,
Object defaultValue)
Gets property value using specified value,
the
ValueExpression 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.
|
static Map<String,Object> |
pushScopedVariables(List<IScopedVariableComponent> components)
Push the given variables into scope
|
static 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 the
ValueExpression 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.
use
stripForms(UIComponent, boolean) instead. |
static void |
stripForms(UIComponent component,
boolean skipDisjointForms)
Recursively replaces any forms in the subtree with generic UINamingContainers.
|
static MethodBinding |
wrapExpression(MethodExpression me)
Deprecated.
|
static ValueBinding |
wrapExpression(ValueExpression ve)
Deprecated.
|
protected static final String VIEW_FRAGMENT_SET
protected static final String ATTR_SHADOW_COMPONENT_MAP
protected static final Pattern RE_TABLE_ROW_INDEX
protected static final Pattern RE_TABLE_ROW_ID
public static void renderComponent(FacesContext ctx, UIComponent component) throws IOException, FacesException
ctx
- Current context.component
- Component to render.IOException
FacesException
public static void renderComponent(FacesContext context, UIComponent component, ResponseWriter writer) throws IOException, FacesException
context
- Current context.component
- Component to render.writer
- Buffer to which to write.IOException
FacesException
public static String renderComponentText(FacesContext ctx, UIComponent component) throws IOException, FacesException
ctx
- Current context.component
- Component to render.IOException
FacesException
public static String renderComponentHTML(FacesContext ctx, UIComponent component) throws IOException, FacesException
ctx
- Current context.component
- Component to render.IOException
FacesException
public static Object getPropertyOrBindingValue(FacesContext context, UIComponent component, String name, Object specifiedValue, Object defaultValue)
ValueExpression
for the specified name,
or the default value.
This method will return null only if the defaultValue is null.context
- Current context.component
- Component for which to the value.name
- Property name.specifiedValue
- User-specified value.defaultValue
- Default value.public static boolean setBindingValue(FacesContext context, UIComponent component, String name, Object value)
ValueExpression
for the specified name, if possible.context
- Current context.component
- Component for which to the value.name
- Property name.value
- Value.public static boolean setBindingValueWithErrorMessage(FacesContext context, UIComponent component, String name, Object value)
public static void baseValidateValue(FacesContext context, UIInput input, Object value)
context
- Current context.input
- UIInput to validate.value
- Value to validate.public static boolean isEmptyValue(Object value)
public static String getFullyQualifiedComponentId(UIComponent uiComponent)
createAbsoluteIdReference(UIComponent)
Returns the fully qualified server-side component id. This ID can be used to
find a component using the UIComponent.findComponent(id) API.uiComponent
- the component to calculate the id forpublic static String createAbsoluteIdReference(FacesContext context, UIComponent source, String relativeId)
context
- Current context.source
- Component from which to start search (or null to start from view root).relativeId
- Relative control id reference.public static String createAbsoluteIdReference(UIComponent uiComponent)
UIComponent.findComponent(String)
.uiComponent
- Component for which to calculate id.public static UIComponent findComponent(FacesContext context, UIComponent source, String reference)
context
- Current context.source
- Component from which to start search (or null to start from view root).reference
- Control id reference.protected static UIComponent findComponentInSubtreeById(FacesContext context, UIComponent source, String id)
context
- Current context.source
- Root of subtree (search includes source).id
- Component id for which to search.protected static UIComponent findComponentInSiblingSubtreeById(FacesContext context, UIComponent source, String id)
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.public static void clearShadowComponentMap(FacesContext context, UIComponent component)
protected static ComponentUtils.ShadowComponentNode getShadowComponentNode(FacesContext context, UIComponent component)
protected static Map<UIComponent,ComponentUtils.ShadowComponentNode> getShadowComponentMap(FacesContext context, UIComponent component)
protected static void buildShadowComponentMap(Map<UIComponent,ComponentUtils.ShadowComponentNode> map, UIComponent component, List<ComponentUtils.ShadowComponentNode> ancestors)
map
- Map to build (starts empty).component
- Subtree root.ancestors
- Ancestor stack (starts empty).public static String createClientId(FacesContext context, UIComponent source, String reference)
context
- Current context.source
- Component from which to start search (or null to start from view root).reference
- Control id reference.public static List<String> createClientIdsList(FacesContext context, UIComponent source, String references)
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.public static boolean isAsyncRequest(FacesContext context)
@Deprecated public static UIComponent getCurrentViewFragment(FacesContext context)
PartialViewContext.getRenderIds()
to get the list of component IDs that
will be rendered by a partial/ajax render response.PartialViewContext.getRenderIds()
to get the full list of component IDs that will be rendered.@Deprecated public static UIComponent getCurrentViewFragmentReinitialized(FacesContext context)
public static void setCurrentViewFragment(FacesContext context, UIComponent component)
public static void applyAnnotations(FacesContext context, UIComponent component, boolean deep)
Application.createComponent(String)
call where the annotations and other
activities are done automatically.context
- faces contextcomponent
- the component to processdeep
- true to also recursively process the children and facets of the component.public static UIComponent copyComponent(FacesContext context, UIComponent sourceComponent) throws InstantiationException, IllegalAccessException
context
- faces contextsourceComponent
- the component to copyInstantiationException
IllegalAccessException
public static UICommand findDefaultCommand(FacesContext context, UIComponent component)
context
- Current context.component
- Component subtree to searchprotected static UICommand findFirstCommand(FacesContext context, UIComponent component)
context
- Current context.component
- Component subtree to search.public static UIForm getForm(FacesContext context, UIComponent component)
context
- Current context.component
- Component whose form to find.public static UIViewRoot getViewRootForComponent(UIComponent component)
component
- Component whose form to find.public static void reparentChildren(UIComponent source, UIComponent destination)
source
- the source componentdestination
- the destination componentpublic static void copyAttributes(UIComponent source, UIComponent destination)
source
- the source componentdestination
- the destination componentpublic static void clearSubmittedValues(UIComponent form)
source
- the control to start frompublic static void stripForms(UIComponent component)
stripForms(UIComponent, boolean)
instead.public static void stripForms(UIComponent component, boolean skipDisjointForms)
public static UINamingContainer replaceWithNamingContainer(UIComponent original, UIComponent replacement)
public static void replaceFormsWithDisjointForms(UIComponent component)
public static DisjointForm replaceWithDisjointForm(UIComponent original, UIComponent replacement)
public static List<IScopedVariableComponent> getAncestorScopedVariableComponents(UIComponent control)
control
- the leaf controlpublic static Map<String,Object> pushScopedVariables(List<IScopedVariableComponent> components)
components
- the list of scoped variable components to processpublic static void popScopedVariables(Map<String,Object> oldVariablesMap)
oldVariablesMap
- the map of old values to restorepublic static Object getStoredPageBeanValue(FacesContext facesContext, String variableName)
value
- of the variable or nullpublic static void setStoredPageBeanValue(FacesContext facesContext, String variableName, Object newValue)
facesContext
- the faces contextvariableName
- the name of the variablenewValue
- of the variable or nullpublic static PageFlowScopeStorage getPageFlowStorage(FacesContext facesContext)
facesContext
- the faces contextpublic static Object getLabel(FacesContext context, UIComponent component)
context
- component
- @Deprecated public static ValueBinding wrapExpression(ValueExpression ve)
ve
- the ValueExpression to wrap@Deprecated public static MethodBinding wrapExpression(MethodExpression me)
ve
- the MethodExpression to wrap