org.kuali.rice.krad.uif.util
Class ComponentUtils

java.lang.Object
  extended by 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)

Constructor Summary
ComponentUtils()
           
 
Method Summary
static
<T extends Field>
void
bindAndIdFieldList(List<T> fields, String addBindingPrefix, String idSuffix)
          Equivalent to copyFieldList(java.util.List, String, String) but does not copy the given list of fields first.
static void clearIds(Component component)
          Clear all ids from a component and its children.
static void clearIds(List<? extends Component> components)
           
static boolean containsPropertyExpression(Component component, String propertyName, boolean collectionMatch)
          Determines whether the given component contains an expression for the given property name
static
<T extends Component>
T
copy(T component)
           
static
<T extends Component>
T
copy(T component, String idSuffix)
           
static
<T extends Component>
T
copyComponent(T component, String addBindingPrefix, String idSuffix)
           
static
<T extends Component>
List<T>
copyComponentList(List<T> components, String idSuffix)
           
static
<T extends Field>
List<T>
copyFieldList(List<T> fields, String idSuffix)
           
static
<T extends Field>
List<T>
copyFieldList(List<T> fields, String addBindingPrefix, String idSuffix)
           
static Component findComponentInList(List<Component> components, String componentId)
          Searches for the component with the given id within the given list of components
static Component findNestedComponentById(Component parent, String nestedId)
          Finds the child component of the given parent component that has the required id
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.
static List<Component> getAllNestedComponents(Component component)
           
static List<String> getComponentPropertyNames(Class<? extends Component> componentClass)
           
static
<T extends Component>
List<T>
getComponentsOfType(List<? extends Component> items, Class<T> componentType)
           
static
<T extends Component>
List<T>
getComponentsOfTypeDeep(Component component, Class<T> componentType)
           
static
<T extends Component>
List<T>
getComponentsOfTypeDeep(List<? extends Component> items, Class<T> componentType)
          Return the components of the specified type from the given component list
protected static
<T> T
getNewInstance(T object)
           
static void prefixBindingPath(DataBinding field, String addBindingPrefix)
           
static void prefixBindingPath(List<? extends Field> fields, String addBindingPrefix)
           
static void prefixBindingPathNested(Component component, String addBindingPrefix)
           
static void pushObjectToContext(Component component, String contextName, Object contextValue)
          pushes object to a component's context so that it is available from Component.getContext()
static void pushObjectToContext(List<? extends Component> components, String contextName, Object contextValue)
          places a key, value pair in each context map of a list of components
static void setComponentPropertyDeep(Component component, String propertyPath, Object propertyValue)
           
static void setComponentsPropertyDeep(List<? extends Component> components, String propertyPath, Object propertyValue)
           
static List<? extends Ordered> sort(List<? extends Ordered> items, int defaultOrderSequence)
          Performs sorting logic of the given list of Ordered instances by its order property
static void updateChildIdsWithSuffixNested(Component component, String idSuffix)
           
static void updateContextForLine(Component component, Object collectionLine, int lineIndex, String lineSuffix)
          update the context map for the given component
static void updateContextsForLine(List<? extends Component> components, Object collectionLine, int lineIndex, String lineSuffix)
          update the contexts of the given components
static void updateIdsWithSuffixNested(Component component, String idSuffix)
           
static void updateIdsWithSuffixNested(List<? extends Component> components, String idSuffix)
           
static void updateIdWithSuffix(Component component, String idSuffix)
          add a suffix to the id
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentUtils

public ComponentUtils()
Method Detail

copy

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

copy

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

getNewInstance

protected static <T> T getNewInstance(T object)

bindAndIdFieldList

public static <T extends Field> void bindAndIdFieldList(List<T> fields,
                                                        String addBindingPrefix,
                                                        String idSuffix)
Equivalent to copyFieldList(java.util.List, String, String) but does not copy the given list of fields first.


copyFieldList

public static <T extends Field> List<T> copyFieldList(List<T> fields,
                                                      String addBindingPrefix,
                                                      String idSuffix)

copyFieldList

public static <T extends Field> List<T> copyFieldList(List<T> fields,
                                                      String idSuffix)

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 extends Component> List<T> getComponentsOfType(List<? extends Component> items,
                                                                Class<T> componentType)

getComponentsOfTypeDeep

public static <T extends Component> List<T> getComponentsOfTypeDeep(List<? extends Component> items,
                                                                    Class<T> componentType)
Return the components of the specified type from the given component list

Components that match, implement or are extended from the specified componentType are returned in the result. If a component is a parent to other components then these child components are searched for matching component types as well.

Type Parameters:
T - the type of the components that are returned
Parameters:
items - list of components from which to search
componentType - the class or interface of the component type to return
Returns:
List of matching components

getComponentsOfTypeDeep

public static <T extends Component> List<T> getComponentsOfTypeDeep(Component component,
                                                                    Class<T> componentType)

getAllNestedComponents

public static List<Component> getAllNestedComponents(Component component)

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

findNestedComponentById

public static Component findNestedComponentById(Component parent,
                                                String nestedId)
Finds the child component of the given parent component that has the required id

Parameters:
parent - parent component for component to find
nestedId - id of the component to find
Returns:
Component instance for child (if found) or null

prefixBindingPath

public static void prefixBindingPath(List<? extends Field> fields,
                                     String addBindingPrefix)

prefixBindingPathNested

public static void prefixBindingPathNested(Component component,
                                           String addBindingPrefix)

prefixBindingPath

public static void prefixBindingPath(DataBinding field,
                                     String addBindingPrefix)

updateIdsWithSuffixNested

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

updateIdsWithSuffixNested

public static void updateIdsWithSuffixNested(Component component,
                                             String idSuffix)

updateChildIdsWithSuffixNested

public static void updateChildIdsWithSuffixNested(Component component,
                                                  String idSuffix)

clearIds

public static void clearIds(Component component)
Clear all ids from a component and its children. If there are features that depend on a static id of this component, this call may cause errors.

Parameters:
component - the component to clear all ids from

clearIds

public static void clearIds(List<? extends Component> components)

updateIdWithSuffix

public static void updateIdWithSuffix(Component component,
                                      String idSuffix)
add a suffix to the id

Parameters:
component - the component instance whose id will be changed
idSuffix - the suffix to be appended

setComponentsPropertyDeep

public static void setComponentsPropertyDeep(List<? extends Component> components,
                                             String propertyPath,
                                             Object propertyValue)

setComponentPropertyDeep

public static void setComponentPropertyDeep(Component component,
                                            String propertyPath,
                                            Object propertyValue)

getComponentPropertyNames

public static List<String> getComponentPropertyNames(Class<? extends Component> componentClass)

pushObjectToContext

public static void pushObjectToContext(List<? extends Component> components,
                                       String contextName,
                                       Object contextValue)
places a key, value pair in each context map of a list of components

Parameters:
components - the list components
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

updateContextsForLine

public static void updateContextsForLine(List<? extends Component> components,
                                         Object collectionLine,
                                         int lineIndex,
                                         String lineSuffix)
update the contexts of the given components

calls updateContextForLine(org.kuali.rice.krad.uif.component.Component, Object, int, String) for each component

Parameters:
components - the components whose components to update
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,
                                        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
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

sort

public static List<? extends Ordered> sort(List<? extends Ordered> 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.

Parameters:
items -
defaultOrderSequence -
Returns:
List sorted items
See Also:
Component.getOrder(), org.springframework.core.Ordered

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.

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


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.