- After you implement treeTable on the jsff page
- Implement RegionListener to jsff page
package com.incbda.myApp.view.ppl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import oracle.adf.model.RegionBinding;
import oracle.adf.model.RegionContext;
import oracle.adf.model.RegionController;
import oracle.adf.view.rich.component.rich.data.RichTree;
import oracle.adf.view.rich.component.rich.data.RichTreeTable;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.jbo.uicli.binding.JUCtrlHierBinding;
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;
import org.apache.myfaces.trinidad.model.CollectionModel;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;
public class ConfigRegionController implements RegionController {
public ConfigRegionController() {
super();
}
private 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 UIComponent getUIComponent(String id) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
return findComponent(facesCtx.getViewRoot(), id);
}
@Override
public boolean refreshRegion(RegionContext regionContext) {
int refreshFlag = regionContext.getRefreshFlag();
if (refreshFlag == RegionBinding.PREPARE_MODEL) {
//PPR tree table
RichTreeTable treeTable = (RichTreeTable) getUIComponent("tt1");
if (treeTable != null) {
CollectionModel model = (CollectionModel) ((RichTreeTable) treeTable).getValue();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) model.getWrappedData();
JUCtrlHierNodeBinding rootNode = treeBinding.getRootNodeBinding();
RowKeySet rks = (((RichTreeTable) treeTable).getDisclosedRowKeys());
if (rks == null) {
rks = new RowKeySetImpl();
}
if (rks.getSize() == 0) {
List<JUCtrlHierNodeBinding> firstLevelChildren = rootNode.getChildren();
for (JUCtrlHierNodeBinding node : firstLevelChildren) {
ArrayList l = new ArrayList();
l.add(node.getRowKey());
rks.add(l);
}
((RichTreeTable) treeTable).setDisclosedRowKeys(rks);
}
}
}
regionContext.getRegionBinding().refresh(refreshFlag);
return true;
}
@Override
public boolean validateRegion(RegionContext regionContext) {
// TODO Implement this method
return false;
}
@Override
public boolean isRegionViewable(RegionContext regionContext) {
// TODO Implement this method
return false;
}
@Override
public String getName() {
// TODO Implement this method
return null;
}
}