ComponentUtils { public static void cleanContextDeap(LifecycleElement lifecycleElement) { if (lifecycleElement == null) { return; } lifecycleElement.setContext(null); Class<?> elementClass = lifecycleElement.getClass(); List<java.lang.reflect.Field> fields = ReflectionUtils.getAllFields(elementClass); for (java.lang.reflect.Field field : fields) { if (Collection.class.isAssignableFrom(field.getType())) { ReflectionUtils.makeAccessible(field); Collection<Object> elements = (Collection<Object>) ReflectionUtils.getField(field, lifecycleElement); if (elements != null) { for (Object element : elements) { if (element != null && LifecycleElement.class.isAssignableFrom(element.getClass())) { cleanContextDeap((LifecycleElement) element); } } } } else if (Map.class.isAssignableFrom(field.getType())) { ReflectionUtils.makeAccessible(field); Map<Object, Object> elements = (Map<Object, Object>) ReflectionUtils.getField(field, lifecycleElement); if (elements != null) { for (Object element : elements.entrySet()) { if (element != null && LifecycleElement.class.isAssignableFrom(element.getClass())) { cleanContextDeap((LifecycleElement) element); } } } } else if (LifecycleElement.class.isAssignableFrom(field.getType())) { ReflectionUtils.makeAccessible(field); LifecycleElement nestedElement = (LifecycleElement) ReflectionUtils.getField(field, lifecycleElement); cleanContextDeap(nestedElement); } } } private  ComponentUtils(); static T copy(T component); static T copy(T component, String idSuffix); static List<T> copy(List<T> components); static void bindAndIdFieldList(List<T> fields, String addBindingPrefix, String idSuffix); static T copyComponent(T component, String addBindingPrefix, String idSuffix); static List<T> copyComponentList(List<T> components, String idSuffix); static List<T> getComponentsOfType(List<? extends Component> items,
            Class<T> componentType); static List<T> getNestedContainerComponents(Container container,
            Class<T> componentType); static List<T> getNestedNonCollectionComponents(List<Component> items,
            Class<T> componentType); static List<T> getNestedNonCollectionComponents(Container container,
            Class<T> componentType); static List<Component> getAllNestedComponents(Component component); static Component findComponentInList(List<Component> components, String componentId); static void prefixBindingPath(List<? extends Component> components, String addBindingPrefix); static void prefixBindingPath(Component component, String addBindingPrefix); static void prefixBindingPath(DataBinding field, String addBindingPrefix); static void prefixBindingPathNested(Component component, String addBindingPrefix); static void updateIdsWithSuffixNested(List<? extends Component> components, String idSuffix); static void updateIdsWithSuffixNested(Component component, String idSuffix); static void updateIdWithSuffix(LifecycleElement element, String idSuffix); static void updateChildIdsWithSuffixNested(Component component, String idSuffix); static int generateId(LifecycleElement element, int seed); static void clearAndAssignIds(List<? extends Component> components); static void setComponentsPropertyDeep(List<T> components, String propertyPath,
            Object propertyValue); static void setComponentPropertyDeep(Component component, String propertyPath, Object propertyValue); static void setComponentPropertyFinal(Component component, String propertyName, Object propertyValue); static boolean canBeRefreshed(Component component); static void pushObjectToContext(Collection<? extends LifecycleElement> elements, String contextName,
            Object contextValue); static void pushObjectToContext(Component component, String contextName, Object contextValue); static void pushAllToContext(List<? extends Component> components, Map<String, Object> sourceContext); static void pushAllToContext(Component component, Map<String, Object> sourceContext); static void updateContextsForLine(List<? extends Component> components, CollectionGroup collectionGroup,
            Object collectionLine, int lineIndex, String lineSuffix); static void updateContextForLine(Component component, CollectionGroup collectionGroup, Object collectionLine,
            int lineIndex, String lineSuffix); static void cleanContextDeap(LifecycleElement lifecycleElement); static List<T> sort(List<T> items, int defaultOrderSequence); static List<InputField> getAllInputFieldsWithinContainer(Container container); static boolean containsPropertyExpression(Component component, String propertyName,
            boolean collectionMatch); static void adjustNestedLevelsForTableCollections(Container container, int currentLevel);  }
@Test public void testCleanContextDeap() { Map<String, Object> context = new HashMap<String, Object>(); context.put("contextkey", "value"); context.put("contextkey2", "value2"); BreadcrumbItem breadcrumbItem = new BreadcrumbItem(); breadcrumbItem.setContext(context); InputField inputField = new InputFieldBase(); inputField.setContext(context); Label fieldLabel = new Label(); fieldLabel.setContext(context); Tooltip labelTootlip = new Tooltip(); labelTootlip.setContext(context); fieldLabel.setToolTip(labelTootlip); inputField.setFieldLabel(fieldLabel); breadcrumbItem.setSiblingBreadcrumbComponent(inputField); Tooltip tooltip = new Tooltip(); tooltip.setContext(context); breadcrumbItem.setToolTip(tooltip); ContextUtils.cleanContextDeep(breadcrumbItem); assertEquals(0, breadcrumbItem.getContext().size()); assertEquals(0, inputField.getContext().size()); assertEquals(0, fieldLabel.getContext().size()); assertEquals(0, labelTootlip.getContext().size()); assertEquals(0, tooltip.getContext().size()); }