Don't use initially expanded property or you will end up suffering with wired behavior using this code:
Tree Table Source:
selectionListener="#{bindings.ReportMenuTreeVO12.treeModel.makeCurrent}"
rowSelection="single" id="tt1" columnSelection="single"
displayRow="selected" autoHeightRows="10"
binding="#{viewScope.treeTableHelperBean.treeTable}"
disclosedRowKeys="#{viewScope.treeTableHelperBean.newDisclosedTreeTableKeys}"
rowDisclosureListener="#{viewScope.treeTableHelperBean.disclosureListener}">
..........................
TreeTableHelper class:
public class TreeTableHelper {
private RowKeySetImpl newDisclosedTreeTableKeys = null;
private RichTreeTable treeTable;
public TreeTableHelper() {
super();
}
public void disclosureListener(RowDisclosureEvent rowDisclosureEvent) {
RichTreeTable treeTable = (RichTreeTable)rowDisclosureEvent.getSource();
RowKeySet rowKeySet = rowDisclosureEvent.getAddedSet();
if (rowKeySet != null && rowKeySet.size() > 0) {
Iterator iterator = rowKeySet.iterator();
while (iterator.hasNext()) {
Object rowKey = iterator.next();
treeTable.setRowKey(rowKey);
JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)treeTable.getRowData();
if (rowData != null && rowData.getChildren() != null) {
for (Object child : rowData.getChildren()) {
JUCtrlHierNodeBinding childNode = (JUCtrlHierNodeBinding)child;
if (childNode.getChildren() == null || childNode.getChildren().size() == 0) {
treeTable.getDisclosedRowKeys().add(childNode.getKeyPath());
}
}
}
}
}
}
public void setNewDisclosedTreeTableKeys(RowKeySetImpl newDisclosedTreeTableKeys) {
this.newDisclosedTreeTableKeys = newDisclosedTreeTableKeys;
}
public RowKeySetImpl getNewDisclosedTreeTableKeys() {
if (newDisclosedTreeTableKeys == null) {
newDisclosedTreeTableKeys = new RowKeySetImpl();
RichTreeTable treeTable = this.getTreeTable();
if (treeTable != null) {
CollectionModel model = (CollectionModel)treeTable.getValue();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)model.getWrappedData();
JUCtrlHierNodeBinding nodeBinding = treeBinding.getRootNodeBinding();
expandAllNodes(nodeBinding, newDisclosedTreeTableKeys, 0, 10);
AdfFacesContext.getCurrentInstance().addPartialTarget(this.getTreeTable());
}
}
return newDisclosedTreeTableKeys;
}
private void expandAllNodes(JUCtrlHierNodeBinding nodeBinding, RowKeySet disclosedKeys, int currentExpandLevel, int maxExpandLevel) {
if (currentExpandLevel <= maxExpandLevel) {
List
childNodes = (List)nodeBinding.getChildren();
ArrayList newKeys = new ArrayList();
if (childNodes != null) {
for (JUCtrlHierNodeBinding _node : childNodes) {
newKeys.add(_node.getKeyPath());
expandAllNodes(_node, disclosedKeys, currentExpandLevel + 1, maxExpandLevel);
}
}
disclosedKeys.addAll(newKeys);
}
}
public void setTreeTable(RichTreeTable treeTable) {
this.treeTable = treeTable;
}
public RichTreeTable getTreeTable() {
return treeTable;
}
}