Class ComponentUtils

java.lang.Object
org.kuali.rice.krad.uif.util.ComponentUtils

public class ComponentUtils extends Object
ComponentUtils is a utility class providing methods to help create and modify Component instances.
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Method Details

    • copy

      public static <T extends Component> T copy(T component)
    • copy

      public static <T extends Component> T copy(T component, String idSuffix)
    • copy

      public static <T extends Component> List<T> copy(List<T> components)
      Copy a list of components
      Type Parameters:
      T - component type
      T - component type
      Parameters:
      components - the list of components to copy
      Returns:
      the copied list
    • bindAndIdFieldList

      public static <T extends Field> void bindAndIdFieldList(List<T> fields, String addBindingPrefix, String idSuffix)
      Adjusts the ids to contain the given suffix and adds the giving binding prefix for the list of fields.
      Type Parameters:
      T - component type
      Parameters:
      fields - list of fields to bind and id
      addBindingPrefix - prefix to add to the binding path
      idSuffix - id suffix
    • copyComponent

      public static <T extends Component> T copyComponent(T component, String addBindingPrefix, String idSuffix)
    • copyComponentList

      public static <T extends Component> List<T> copyComponentList(List<T> components, String idSuffix)
    • getComponentsOfType

      public static <T> List<T> getComponentsOfType(List<? extends Component> items, Class<T> componentType)
    • getNestedContainerComponents

      public static <T extends Component> List<T> getNestedContainerComponents(Container container, Class<T> componentType)
      Gets all components of the give type that are within the items list of the container, or within a nested container or field group.
      Type Parameters:
      T - type for component to pull
      Parameters:
      container - container instance to pull components from
      componentType - type for components to pull
      Returns:
      List of nested components with the given type
    • getNestedNonCollectionComponents

      public static <T extends Component> List<T> getNestedNonCollectionComponents(List<Component> items, Class<T> componentType)
    • getNestedNonCollectionComponents

      public static <T extends Component> List<T> getNestedNonCollectionComponents(Container container, Class<T> componentType)
    • getAllNestedComponents

      public static List<Component> getAllNestedComponents(Component component)
      Get all nested children of a given component.
      Parameters:
      component - The component to search.
      Returns:
      All nested children of the component.
      See Also:
    • findComponentInList

      public static Component findComponentInList(List<Component> components, String componentId)
      Searches for the component with the given id within the given list of components
      Parameters:
      components - list of components to search through
      componentId - id for the component to find
      Returns:
      component found in the list or null
    • prefixBindingPath

      public static void prefixBindingPath(List<? extends Component> components, String addBindingPrefix)
    • prefixBindingPath

      public static void prefixBindingPath(Component component, String addBindingPrefix)
    • prefixBindingPath

      public static void prefixBindingPath(DataBinding field, String addBindingPrefix)
    • prefixBindingPathNested

      public static void prefixBindingPathNested(Component component, String addBindingPrefix)
    • updateIdsWithSuffixNested

      public static void updateIdsWithSuffixNested(List<? extends Component> components, String idSuffix)
    • updateIdsWithSuffixNested

      public static void updateIdsWithSuffixNested(Component component, String idSuffix)
    • updateIdWithSuffix

      public static void updateIdWithSuffix(LifecycleElement element, String idSuffix)
      add a suffix to the id
      Parameters:
      element - the component instance whose id will be changed
      idSuffix - the suffix to be appended
    • updateChildIdsWithSuffixNested

      public static void updateChildIdsWithSuffixNested(Component component, String idSuffix)
    • generateId

      public static int generateId(LifecycleElement element, int seed)
      Generate a hash code unique within the current view for a single lifecycle element. A unique ID value will be assigned to the lifecycle element, replacing the current ID.

      This method may only be called during the view lifecycle.

      Parameters:
      element - The element to generate a hash code for.
      seed - A hash value to use as a seed for the new hash.
      Returns:
      A hash code based on the provided element and seed value.
      See Also:
    • clearAndAssignIds

      public static void clearAndAssignIds(List<? extends Component> components)
      Replace all IDs from a component and its children with new generated ID values.

      If there are features that depend on a static id of this component, this call may cause errors.

      Parameters:
      components - A list of component to clear all IDs from.
      See Also:
    • setComponentsPropertyDeep

      public static <T extends Component> void setComponentsPropertyDeep(List<T> components, String propertyPath, Object propertyValue)
      Traverse a component tree, setting a property on all components for which the property is writable.
      Type Parameters:
      T - component type
      T - component type
      Parameters:
      components - The components to traverse.
      propertyPath - The property path to set.
      propertyValue - The property value to set.
      See Also:
    • setComponentPropertyDeep

      public static void setComponentPropertyDeep(Component component, String propertyPath, Object propertyValue)
      Traverse a component tree, setting a property on all components for which the property is writable.
      Parameters:
      component - The component to traverse.
      propertyPath - The property path to set.
      propertyValue - The property value to set.
      See Also:
    • setComponentPropertyFinal

      public static void setComponentPropertyFinal(Component component, String propertyName, Object propertyValue)
      Sets a property on the given component and removes any expressions for that property so the value is not overridden
      Parameters:
      component - component instance to set property on
      propertyName - name of property to set
      propertyValue - value to set property to
    • canBeRefreshed

      public static boolean canBeRefreshed(Component component)
      Indicates if the given component has configuration that it allows it to be refreshed.
      Parameters:
      component - instance to check
      Returns:
      true if component can be refreshed, false if not
    • pushObjectToContext

      public static void pushObjectToContext(Collection<? extends LifecycleElement> elements, String contextName, Object contextValue)
      places a key, value pair in each context map of a list of components
      Parameters:
      elements - the list of elements
      contextName - a value to be used as a key to retrieve the object
      contextValue - the value to be placed in the context
    • pushObjectToContext

      public static void pushObjectToContext(Component component, String contextName, Object contextValue)
      pushes object to a component's context so that it is available from Component.getContext()

      The component's nested components that are available via Component#getComponentsForLifecycle are also updated recursively

      Parameters:
      component - the component whose context is to be updated
      contextName - a value to be used as a key to retrieve the object
      contextValue - the value to be placed in the context
    • pushAllToContext

      public static void pushAllToContext(List<? extends Component> components, Map<String,Object> sourceContext)
      places a all entries from a map into each context map of a list of components
      Parameters:
      components - The list components.
      sourceContext - The source context map.
    • pushAllToContext

      public static void pushAllToContext(Component component, Map<String,Object> sourceContext)
      pushes object to a component's context so that it is available from Component.getContext()

      The component's nested components that are available via Component#getComponentsForLifecycle are also updated recursively

      Parameters:
      component - the component whose context is to be updated
      sourceContext - The source context map.
    • updateContextsForLine

      public static void updateContextsForLine(List<? extends Component> components, CollectionGroup collectionGroup, Object collectionLine, int lineIndex, String lineSuffix)
      Parameters:
      components - the components whose components to update
      collectionGroup - collection group the components are associated with
      collectionLine - an instance of the data object for the line
      lineIndex - the line index
      lineSuffix - id suffix for components in the line to make them unique
    • updateContextForLine

      public static void updateContextForLine(Component component, CollectionGroup collectionGroup, Object collectionLine, int lineIndex, String lineSuffix)
      update the context map for the given component

      The values of UifConstants.ContextVariableNames.LINE and UifConstants.ContextVariableNames.INDEX are set to collectionLine and lineIndex respectively.

      Parameters:
      component - the component whose context is to be updated
      collectionGroup - collection group the component is associated with
      collectionLine - an instance of the data object for the line
      lineIndex - the line index
      lineSuffix - id suffix for components in the line, not if the collection group has a container id suffix it will be appended to the lineSuffix for the final exported context entry
    • cleanContextDeap

      public static void cleanContextDeap(LifecycleElement lifecycleElement)
      Sets the context of the given lifecycle element to null, then using reflection recursively finds any lifecycle element children and sets their context to null.
      Parameters:
      lifecycleElement - lifecycle element instance to clean
    • sort

      public static <T extends Ordered> List<T> sort(List<T> items, int defaultOrderSequence)
      Performs sorting logic of the given list of Ordered instances by its order property

      Items list is sorted based on its order property. Lower order values are placed higher in the list. If a item does not have a value assigned for the order (or is equal to the default order of 0), it will be assigned the a value based on the given order sequence integer. If two or more items share the same order value, all but the last item found in the list will be removed.

      Type Parameters:
      T - ordered type
      Returns:
      List<Ordered> sorted items
      See Also:
    • getAllInputFieldsWithinContainer

      public static List<InputField> getAllInputFieldsWithinContainer(Container container)
      Gets all the input fields contained in this container, but also in every sub-container that is a child of this container. When called from the top level View this will be every InputField across all pages.
      Parameters:
      container - container to scan for input fields
      Returns:
      every InputField that is a child at any level of this container
    • containsPropertyExpression

      public static boolean containsPropertyExpression(Component component, String propertyName, boolean collectionMatch)
      Determines whether the given component contains an expression for the given property name
      Parameters:
      component - component instance to check for expressions
      propertyName - name of the property to determine if there is an expression for
      collectionMatch - if set to true will find an expressions for properties that start with the given property name (for matching expressions on collections like prop[index] or prop['key'])
      Returns:
      true if the component has an expression for the property name, false if not
    • adjustNestedLevelsForTableCollections

      public static void adjustNestedLevelsForTableCollections(Container container, int currentLevel)
      Adjust nestingLevel properties for collections which use RichTable with forceLocalJsonData on and for all of its potentially additional nested subcollections
      Parameters:
      container - container to traverse and update nested levels in
      currentLevel - the current nesting level, the initial call to this method should be 0