Author: nbelaevski
Date: 2009-04-23 13:43:37 -0400 (Thu, 23 Apr 2009)
New Revision: 13805
Modified:
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
Log:
https://jira.jboss.org/jira/browse/RF-5771
Modified: trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java
===================================================================
---
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2009-04-23
17:06:33 UTC (rev 13804)
+++
trunk/framework/api/src/main/java/org/richfaces/model/StackingTreeModel.java 2009-04-23
17:43:37 UTC (rev 13805)
@@ -37,6 +37,8 @@
import org.ajax4jsf.model.Range;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.iterators.FilterIterator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.w3c.dom.NamedNodeMap;
/**
@@ -288,14 +290,16 @@
TreeRange treeRange = (TreeRange) range;
if (treeRange == null || treeRange.processNode(argumentKey)) {
- getRoot().setRowKey(context, argumentKey);
+ StackingTreeModel rootModel = getRoot();
+
+ rootModel.setRowKey(context, argumentKey);
if (argumentKey != null) {
processElement(context, dataVisitor, argument, argumentKey, last);
}
//setup key in order for nested components to initialize data models
- getRoot().setRowKey(context, argumentKey);
+ rootModel.setRowKey(context, argumentKey);
final ShiftingDataVisitor shiftingDataVisitor = new ShiftingDataVisitor(
new Visitor1(dataVisitor));
@@ -305,7 +309,7 @@
while (iterator.hasNext()) {
final StackingTreeModel model = iterator.next();
- getRoot().setRowKey(context, argumentKey);
+ rootModel.setRowKey(context, argumentKey);
final ExtendedDataModel scalarModel = model.getDataModel();
Argument argument2 = new Argument();
@@ -365,20 +369,70 @@
return models.values().iterator();
}
+ private static final Log keyBackupVisitorLog =
LogFactory.getLog(KeyBackupVisitor.class);
+
+ private class KeyBackupVisitor implements DataVisitor, LastElementAware {
+
+ private ExtendedDataModel dataModel;
+
+ private Object rowKey;
+
+ private DataVisitor dataVisitor;
+
+ private boolean last;
+
+ public KeyBackupVisitor(ExtendedDataModel dataModel,
+ DataVisitor dataVisitor) {
+ super();
+
+ this.dataModel = dataModel;
+ this.rowKey = dataModel.getRowKey();
+ this.dataVisitor = dataVisitor;
+ }
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ this.dataModel.setRowKey(this.rowKey);
+ try {
+ processElement(context, this.dataVisitor, argument, (TreeRowKey<?>) rowKey,
this.last);
+ } finally {
+ try {
+ this.rowKey = this.dataModel.getRowKey();
+ } catch (Exception e) {
+ keyBackupVisitorLog.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ public void resetLastElement() {
+ this.last = false;
+ }
+
+ public void setLastElement() {
+ this.last = true;
+ }
+
+ }
+
public void walk(FacesContext context, DataVisitor dataVisitor,
Range range, Object rowKey, Object argument,
boolean last) throws IOException {
+ StackingTreeModel rootModel = getRoot();
+ KeyBackupVisitor backupVisitor = new KeyBackupVisitor(rootModel, dataVisitor);
+
if (rowKey != null) {
ListRowKey listRowKey = (ListRowKey) rowKey;
- StackingTreeModel treeModel = getRoot().setupKey(listRowKey, context);
+ StackingTreeModel treeModel = rootModel.setupKey(listRowKey, context);
- treeModel.doWalk(context, dataVisitor, range, listRowKey, argument,
+ treeModel.doWalk(context, backupVisitor, range, listRowKey, argument,
last);
} else {
- doWalk(context, dataVisitor, range, (ListRowKey) rowKey, argument, last);
+ doWalk(context, backupVisitor, range,
+ (ListRowKey) rowKey, argument, last);
}
}