Clean the value of invisible items

Here is a code that you can use to clean the values of some elements if you have a structure of questions that are showing/hiding based on selection.

The approach is to have a main component that contains the tree of questions. The component id will be provided.

There is one issue regarding the inheritance of visible parameters in ADF 11, looks like if you have a panelGroupLayout that is visible=false, the components inside are not having visible=false. (No comment on that).

Hope you find it useful. The cleaning of the value is just for some of the components, check the clean method.
public static void cleanInvisibleItems(String componentId) {
UIComponent component = findComponentInRoot(componentId);
if (component != null) {
List<UIComponent> list = component.getChildren();

public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;

FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
component = findComponent(root, id);
return component;

// find a UIComponent inside a UIComponent
public static UIComponent findComponent(UIComponent base, String id) {
if (id.equals(base.getId()))
return base;

UIComponent children = null;
UIComponent result = null;
Iterator childrens = base.getFacetsAndChildren();
while (childrens.hasNext() && (result == null)) {
children = (UIComponent);
if (id.equals(children.getId())) {
result = children;
result = findComponent(children, id);
if (result != null) {
return result;

private static void parseTree(List<UIComponent> list) {

List<UIComponent> levelChildren = new ArrayList<UIComponent>();
for (UIComponent elem : list) {
boolean toClean = false;
if (elem instanceof RichPanelGroupLayout) {
RichPanelGroupLayout comp0 = (RichPanelGroupLayout)elem;
if (!comp0.isVisible()) {
toClean = true;
if (!toClean) {
List<UIComponent> children = elem.getChildren();
addTolistChildren(levelChildren, children);



private static void addTolistChildren(List<UIComponent> levelChildren, List<UIComponent> children) {
for (UIComponent child : children) {

private static void clean(UIComponent elem) {
List<UIComponent> children = elem.getChildren();
for (UIComponent child : children) {
if (child instanceof RichSelectOneRadio) {
RichSelectOneRadio comp = (RichSelectOneRadio)child;
} else if (child instanceof RichSelectManyCheckbox) {
RichSelectManyCheckbox comp = (RichSelectManyCheckbox)child;
} else if (child instanceof RichSelectBooleanCheckbox) {
RichSelectBooleanCheckbox comp = (RichSelectBooleanCheckbox)child;
} else if (child instanceof RichSelectManyListbox) {
RichSelectManyListbox comp = (RichSelectManyListbox)child;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s