Getting an iterator and passing through it

Here you have some code for getting the iterator by name go through the values.

DCIteratorBinding iter = findIterator(“YOUR_ITERATOR_NAME”);

Row[] rows = iter.getAllRowsInRange();
for (Row row : rows) { // do something here }

/**
* Find an iterator binding in the current binding container by name.
*
* @param name iterator binding name
* @return iterator binding
*/
public static DCIteratorBinding findIterator(String name) {
DCIteratorBinding iter = getDCBindingContainer().findIteratorBinding(name);
if (iter == null) {
throw new RuntimeException(“Iterator ‘” + name + “‘ not found”);
}
return iter;
}

/**
* Return the current page’s binding container.
* @return the current page’s binding container
*/
private static BindingContainer getBindingContainer() {
BindingContext bc = BindingContext.getCurrent();
return bc.getCurrentBindingsEntry();
}

/**
* Return the Binding Container as a DCBindingContainer.
* @return current binding container as a DCBindingContainer
*/
public static DCBindingContainer getDCBindingContainer() {
return (DCBindingContainer)getBindingContainer();
}

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();
parseTree(list);
}
}

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)childrens.next();
if (id.equals(children.getId())) {
result = children;
break;
}
result = findComponent(children, id);
if (result != null) {
break;
}
}
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;
clean(elem);
}
}
if (!toClean) {
List<UIComponent> children = elem.getChildren();
addTolistChildren(levelChildren, children);
parseTree(levelChildren);
}

}

}

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

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

Passing a parameter from EL ADF 11.1.1.7

Passing a parameter from EL (expression language) so that you can handle the current value considering that you have a table and for each row you have to enable or disable a button based on the parameter provided.

-Code in the fragment.

<af:column sortable=”false” headerText=”Actions” id=”c5″>
<af:commandButton text=”ADD” id=”cb3″
disabled=”#{pageFlowScope.taskDetailsBean.showBtn[row.Id] eq ‘false’}”/>
</af:column>

-Code in managed bean

public Map getShowBtn() {
return new HashMap<Long, String>() {
@Override
public String get(Object key) {
Number id = (Number)key;
if (processSelected.contains(id))
return “false”;
else
return “true”;
}
};
}

This is only for ADF 11, currently in 12c it’s much simple,