Class ComponentUtils

java.lang.Object
com.webmethods.caf.faces.component.util.ComponentUtils

public class ComponentUtils extends Object
Component utility functions.
  • Field Details

    • VIEW_FRAGMENT_SET

      protected static final String VIEW_FRAGMENT_SET
      See Also:
    • ATTR_SHADOW_COMPONENT_MAP

      protected static final String ATTR_SHADOW_COMPONENT_MAP
      See Also:
    • RE_TABLE_ROW_INDEX

      protected static final Pattern RE_TABLE_ROW_INDEX
    • RE_TABLE_ROW_ID

      protected static final Pattern 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, the ValueExpression 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 the ValueExpression 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

      public static void baseValidateValue(FacesContext context, UIInput input, Object value)
      Base UIInput validation.
      Parameters:
      context - Current context.
      input - UIInput to validate.
      value - Value to validate.
    • isEmptyValue

      public static boolean isEmptyValue(Object value)
      Returns true if specified value is an empty input value. Empty values are null, empty string (""), empty collection, or empty array.
    • getFullyQualifiedComponentId

      public 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.
      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

      public static String createAbsoluteIdReference(UIComponent uiComponent)
      Creates an absolute component id reference. This id can be used to find a component using UIComponent.findComponent(String).
      Parameters:
      uiComponent - Component for which to calculate id.
      Returns:
      Absolute id reference, or null if component is null.
    • findComponent

      public static UIComponent findComponent(FacesContext context, UIComponent source, String reference)
      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

      public static void clearShadowComponentMap(FacesContext context, UIComponent component)
      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

      public static String createClientId(FacesContext context, UIComponent source, String reference)
      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

      public static boolean isAsyncRequest(FacesContext context)
      True if current request is an async request.
    • getCurrentViewFragment

      @Deprecated public 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.
      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 use PartialViewContext.getRenderIds() to get the full list of component IDs that will be rendered.
    • getCurrentViewFragmentReinitialized

      @Deprecated public static UIComponent getCurrentViewFragmentReinitialized(FacesContext context)
      Deprecated.
      (since 9.10) This is no longer used by the partial/ajax response rendering
      Returns current view fragment, with reinitialized table states.
    • setCurrentViewFragment

      public static void setCurrentViewFragment(FacesContext context, UIComponent component)
      Sets current view fragment.
    • applyAnnotations

      public static void applyAnnotations(FacesContext context, UIComponent component, boolean deep)
      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 the Application.createComponent(String) call where the annotations and other activities are done automatically.
      Parameters:
      context - faces context
      component - the component to process
      deep - 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 context
      sourceComponent - the component to copy
      Returns:
      a copy of the source component
      Throws:
      InstantiationException
      IllegalAccessException
    • findDefaultCommand

      public static UICommand findDefaultCommand(FacesContext context, UIComponent component)
      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

      protected static UICommand findFirstCommand(FacesContext context, UIComponent component)
      Finds the first command for the specified subtree.
      Parameters:
      context - Current context.
      component - Component subtree to search.
      Returns:
      First command component or null.
    • getForm

      public static UIForm getForm(FacesContext context, UIComponent component)
      Finds the form containing the specified component.
      Parameters:
      context - Current context.
      component - Component whose form to find.
      Returns:
      Form or null.
    • getViewRootForComponent

      public static UIViewRoot getViewRootForComponent(UIComponent component)
      Finds the ViewRoot containing the specified component.
      Parameters:
      component - Component whose form to find.
      Returns:
      UIViewRoot or null.
    • reparentChildren

      public static void reparentChildren(UIComponent source, UIComponent destination)
      Moves all the children of the source component to the destination component.
      Parameters:
      source - the source component
      destination - the destination component
    • copyAttributes

      public static void copyAttributes(UIComponent source, UIComponent destination)
      Copy all the attributes from the source component to the destination component
      Parameters:
      source - the source component
      destination - the destination component
    • clearSubmittedValues

      public static void clearSubmittedValues(UIComponent form)
      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

      public static void stripForms(UIComponent component)
      Deprecated.
      Recursively replaces any forms in the subtree with generic UINamingContainers.
    • stripForms

      public static void stripForms(UIComponent component, boolean skipDisjointForms)
      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

      public static void replaceFormsWithDisjointForms(UIComponent component)
      Recursively replaces any forms in the subtree with disjoint forms.
      Since:
      8.2 GA
    • replaceWithDisjointForm

      public 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.
    • 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

      public static Map<String,Object> pushScopedVariables(List<IScopedVariableComponent> components)
      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

      public static void popScopedVariables(Map<String,Object> oldVariablesMap)
      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

      public static Object getStoredPageBeanValue(FacesContext facesContext, String variableName)
      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 context
      variableName - the name of the variable
      newValue - of the variable or null
    • getPageFlowStorage

      public static PageFlowScopeStorage getPageFlowStorage(FacesContext facesContext)
      Gets the active page flow storage object
      Parameters:
      facesContext - the faces context
      Returns:
      the page flow storage object
    • getLabel

      public static Object getLabel(FacesContext context, UIComponent component)
      Return the label of the component or the clientId if no label is supplied.
      Parameters:
      context -
      component -
      Returns:
    • wrapExpression

      @Deprecated public static ValueBinding wrapExpression(ValueExpression ve)
      Deprecated.
      Convert a ValueExpression to a ValueBinding
      Parameters:
      ve - the ValueExpression to wrap
      Returns:
      the ValueBinding equivalent
    • wrapExpression

      @Deprecated public static MethodBinding wrapExpression(MethodExpression me)
      Deprecated.
      Convert a MethodExpression to a MethodBinding
      Parameters:
      ve - the MethodExpression to wrap
      Returns:
      the MethodBinding equivalent