String path, Set ids, Set renderedAreas) throws IOException {
super.encodeAjaxChildren(context, component, path, ids, renderedAreas);
try {
if (component instanceof UITree) {
UITree tree = (UITree) component;
String id = path + tree.getId();
tree.captureOrigValue();
//Object rowKey = tree.getRowKey();
boolean encodeScripts = false;
tree.setRowKey(context, null);
//we should add xmlns to AJAX response
//we'll write neutral inner element and add xmlns there
ResponseWriter responseWriter = context.getResponseWriter();
responseWriter.startElement("div", tree);
writeNamespace(context, component);
List encodedAreaIds = new ArrayList();
try {
List<RowKeyHolder> keyHoldersList = getKeyHoldersList(
tree.getAllAjaxKeys(),
tree.getAllAjaxNodeKeys(),
id);
Collections.sort(keyHoldersList, new Comparator<RowKeyHolder>() {
public int compare(RowKeyHolder o1, RowKeyHolder o2) {
int d1 = o1.rowKey == null ? 0 : o1.rowKey.depth();
int d2 = o2.rowKey == null ? 0 : o2.rowKey.depth();
return d1 < d2 ? -1 : (d2 > d1 ? 1 : 0);
}
});
List<RowKeyHolder> holders = new ArrayList<RowKeyHolder>();
for (RowKeyHolder holder : keyHoldersList) {
boolean isSubKey = false;
for (RowKeyHolder rowKeyHolder : holders) {
if (rowKeyHolder.rowKey == null ||
rowKeyHolder.rowKey.isSubKey(holder.rowKey)) {
isSubKey = true;
break;
}
}
if (!isSubKey) {
holders.add(holder);
}
}
Iterator<RowKeyHolder> ajaxKeysItr = holders.iterator();
while (ajaxKeysItr.hasNext()) {
RowKeyHolder keyHolder = ajaxKeysItr.next();
TreeRowKey key = keyHolder.getRowKey();
if (key != null && key.depth() == 0) {
key = null;
}
tree.setRowKey(context, key);
if (key == null || tree.isRowAvailable()) {
String treeClientId;
if (key == null) {
treeClientId = tree.getClientId(context);
} else {
treeClientId = tree.getNodeFacet().getClientId(context);
}
encodeScripts = true;
//should be added before children id
renderedAreas.add(treeClientId);
if (keyHolder.isNodeKey()) {
writeContent(context, tree, key, false);
} else {
writeContent(context, tree, key, true);
String treeChildrenId = treeClientId + NamingContainer.SEPARATOR_CHAR + "childs";
renderedAreas.add(treeChildrenId);
}
//add node to set of nodes refreshed by script
encodedAreaIds.add(treeClientId);
} else {
String cid = tree.getClientId(context);
String message = MessageFormat.format(
"Failed to re-render tree node: {0} due to model data unavailability! " +
"Maybe parent node should be re-rendered instead?",
new Object[] { cid });
ExternalContext externalContext = context.getExternalContext();
externalContext.log(message);
}
}
//ajaxKeys.clear();
} catch (Exception e) {
throw new FacesException(e);
} finally {
try {
tree.setRowKey(context, null);
tree.restoreOrigValue();
} catch (Exception e) {
context.getExternalContext().log(e.getMessage(), e);
}
}
if (encodeScripts) {
writeScript(context, tree, encodedAreaIds, renderedAreas);
}
responseWriter.endElement("div");
tree.clearRequestKeysSet();
}
} finally {
try {
ComponentsVariableResolver.removeVariables(this, component);
} catch (Exception e) {