Author: vbaranov
Date: 2008-04-09 05:03:29 -0400 (Wed, 09 Apr 2008)
New Revision: 7684
Modified:
branches/3.1.x/ui/tree/src/main/config/component/tree.xml
branches/3.1.x/ui/tree/src/main/java/org/richfaces/component/UITree.java
Log:
http://jira.jboss.com/jira/browse/RF-3004
Modified: branches/3.1.x/ui/tree/src/main/config/component/tree.xml
===================================================================
--- branches/3.1.x/ui/tree/src/main/config/component/tree.xml 2008-04-09 00:25:30 UTC (rev
7683)
+++ branches/3.1.x/ui/tree/src/main/config/component/tree.xml 2008-04-09 09:03:29 UTC (rev
7684)
@@ -66,8 +66,15 @@
<name>rowKeyVar</name>
<classname>java.lang.String</classname>
<description>The attribute provides access to a row key in a Request
scope</description>
- </property>
+ </property>
<property>
+ <name>treeNodeVar</name>
+ <classname>java.lang.String</classname>
+ <description>
+ The attribute provides access to a TreeNode instance in a Request scope
+ </description>
+ </property>
+ <property>
<name>componentState</name>
<classname>org.ajax4jsf.model.DataComponentState</classname>
<description>It defines EL-binding for a component state for saving or
redefinition</description>
Modified: branches/3.1.x/ui/tree/src/main/java/org/richfaces/component/UITree.java
===================================================================
--- branches/3.1.x/ui/tree/src/main/java/org/richfaces/component/UITree.java 2008-04-09
00:25:30 UTC (rev 7683)
+++ branches/3.1.x/ui/tree/src/main/java/org/richfaces/component/UITree.java 2008-04-09
09:03:29 UTC (rev 7684)
@@ -22,9 +22,7 @@
package org.richfaces.component;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.faces.application.Application;
@@ -37,6 +35,7 @@
import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
import javax.faces.event.PhaseId;
+import javax.faces.model.DataModel;
import org.ajax4jsf.component.AjaxComponent;
import org.ajax4jsf.component.UIDataAdaptor;
@@ -65,7 +64,6 @@
import org.richfaces.event.NodeSelectedListener;
import org.richfaces.event.TreeListenerEventsProducer;
import org.richfaces.model.AbstractTreeDataModel;
-import org.richfaces.model.ListRowKey;
import org.richfaces.model.StackingTreeModel;
import org.richfaces.model.StackingTreeModelProvider;
import org.richfaces.model.TreeDataModel;
@@ -108,6 +106,18 @@
public final static String DEFAULT_HIGHLIGHTED_CSS_CLASS = "dr-tree-i-hl";
private UITreeNode defaultFacet;
+
+ /**
+ * Name of EL variable for the tree node. This reference is needed to
+ * let this parent class know about the attributes defined in the
+ * subclass
+ */
+ private String _treeNodeVar;
+
+ /**
+ * Stored state of "treeNodeVar" attribute
+ */
+ private Object treeNodeVarOrigValue = null;
public UITree() {
super();
@@ -119,11 +129,29 @@
public boolean getRendersChildren() {
return true;
}
+
+ /**
+ * Get name of EL variable for the tree node.
+ *
+ * @return the varState
+ */
+ public String getTreeNodeVar() {
+ return _treeNodeVar;
+ }
/**
- * Lazily creates default node representation that is used if there is no
- * {@link UITreeNode} child for that nodeFace
+ * Set the name of EL variable
*
+ * @param treeNodeVar the varStatus to set
+ */
+ public void setTreeNodeVar(String treeNodeVar) {
+ this._treeNodeVar = treeNodeVar;
+ }
+
+ /**
+ * Lazily creates default node representation that is used if there is
+ * no {@link UITreeNode} child for that nodeFace
+ *
* @return created or existing node representation component
*/
protected UITreeNode getOrCreateDefaultFacet() {
@@ -274,6 +302,35 @@
return getOrCreateDefaultFacet();
}
+ /**
+ * Setup EL variable for different iteration. Value of row tree node is
+ * put into request scope attributes with name "treeNodeVar" bean
+ * property. All other attributes are processed in parent
+ * <code>UIDataAdaptor</code> class
+ *
+ * @param faces - current faces context
+ * @param localModel - reference to data model
+ * @param rowSelected - boolean flag indicating whether the row is selected
+ */
+ protected void setupVariable(FacesContext faces, DataModel localModel, boolean
rowSelected) {
+ super.setupVariable(faces, localModel, rowSelected);
+ // get the map storing the request scope
+ // attributes
+ Map attrs = faces.getExternalContext().getRequestMap();
+
+ String treeNodeVar = getTreeNodeVar();
+ if (rowSelected) {
+ // Current row tree node.
+ if (treeNodeVar != null) {
+ attrs.put(treeNodeVar, getTreeNode());
+ }
+ } else {
+ if (treeNodeVar != null) {
+ attrs.remove(treeNodeVar);
+ }
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -508,7 +565,56 @@
public boolean hasAjaxSubmitSelection() {
return isAjaxSubmitSelection();
}
+
+ /**
+ * Save current state of data variable. Overrides the implementation in
+ * the base class for the case the base implementation will be changed.
+ */
+ public void captureOrigValue() {
+ this.captureOrigValue(FacesContext.getCurrentInstance());
+ }
+ /**
+ * Save current state of data variable.
+ *
+ * @param faces current faces context
+ */
+ public void captureOrigValue(FacesContext faces) {
+ super.captureOrigValue(faces);
+ String treeNodeVar = getTreeNodeVar();
+ if (treeNodeVar != null) {
+ Map attrs = faces.getExternalContext().getRequestMap();
+ this.treeNodeVarOrigValue = attrs.get(treeNodeVar);
+ }
+ }
+
+ /**
+ * Restore value of data variable after processing phase. Overrides the
+ * implementation in the base class for the case the base implementation
+ * will be changed.
+ */
+ public void restoreOrigValue() {
+ this.restoreOrigValue(FacesContext.getCurrentInstance());
+ }
+
+ /**
+ * Restore value of data variable after processing phase.
+ *
+ * @param faces current faces context
+ */
+ public void restoreOrigValue(FacesContext faces) {
+ super.restoreOrigValue(faces);
+ String treeNodeVar = getTreeNodeVar();
+ if (treeNodeVar != null) {
+ Map attrs = faces.getExternalContext().getRequestMap();
+ if (this.treeNodeVarOrigValue != null) {
+ attrs.put(treeNodeVar, this.treeNodeVarOrigValue);
+ } else {
+ attrs.remove(treeNodeVar);
+ }
+ }
+ }
+
private ExtendedDataModel createDataModel(boolean allowCached) {
Object value = this.getValue();
if (value != null) {
@@ -521,7 +627,7 @@
return treeDataModel;
} else {
- //TODO implement request caching
+ // TODO implement request caching
StackingTreeModel stackingTreeModel = new VisualStackingTreeModel(null);
if (getChildCount() > 0) {
Iterator children = getChildren().iterator();
@@ -785,9 +891,10 @@
public Object saveState(FacesContext faces) {
- Object[] state = new Object[2];
+ Object[] state = new Object[3];
state[0] = super.saveState(faces);
state[1] = saveAttachedState(faces, defaultFacet);
+ state[2] = getTreeNodeVar();
return state;
}
@@ -802,6 +909,7 @@
defaultFacet.getChildren().add(createDefaultNodeFaceOutput(faces));
defaultFacet.setParent(this);
}
+ setTreeNodeVar((String) state[2]);
}
public String getResolvedDragIndicator(FacesContext facesContext) {