Index: src/java/org/apache/myfaces/custom/tree2/TreeModel.java
===================================================================
--- src/java/org/apache/myfaces/custom/tree2/TreeModel.java	(revision 227400)
+++ src/java/org/apache/myfaces/custom/tree2/TreeModel.java	(working copy)
@@ -15,6 +15,8 @@
  */
 package org.apache.myfaces.custom.tree2;
 
+import java.io.Serializable;
+
 /**
  * Model class for the tree component.  It provides random access to nodes in a tree
  * made up of instances of the {@link TreeNode} class.
@@ -22,7 +24,7 @@
  * @author Sean Schofield
  * @version $Revision$ $Date$
  */
-public interface TreeModel
+public interface TreeModel extends Serializable
 {
     /**
      * Gets the current {@link TreeNode} or <code>null</code> if no node ID is selected.
@@ -56,4 +58,17 @@
      */
     public boolean isLastChild(String nodeId);
 
+    /**
+     * Indicates whether or not the specified {@link TreeNode} is expanded.
+     * 
+     * @param nodeId The id of the node in question.
+     * @return If the node is expanded.
+     */
+    public boolean isNodeExpanded(String nodeId);
+    
+    /**
+     * Toggle the expanded state of the specified {@link TreeNode}.
+     * @param nodeId The id of the node whose expanded state should be toggled.
+     */
+    public void toggleExpanded(String nodeId);
 }
Index: src/java/org/apache/myfaces/custom/tree2/HtmlTree.java
===================================================================
--- src/java/org/apache/myfaces/custom/tree2/HtmlTree.java	(revision 227400)
+++ src/java/org/apache/myfaces/custom/tree2/HtmlTree.java	(working copy)
@@ -40,7 +40,7 @@
     private static final String NODE_STATE_KEY = "org.apache.myfaces.tree.NODE_STATE_KEY";
     private UICommand _expandControl;
     private String _varNodeToggler;
-    private HashSet _expandedNodes = new HashSet();
+//    private HashSet _expandedNodes = new HashSet();
     private String _selectedNodeId;
 
     /**
@@ -56,11 +56,11 @@
     // see superclass for documentation
     public Object saveState(FacesContext context)
     {
-        Object values[] = new Object[4];
+        Object values[] = new Object[3];
         values[0] = super.saveState(context);
-        values[1] = _expandedNodes;
-        values[2] = _varNodeToggler;
-        values[3] = _selectedNodeId;
+//        values[1] = _expandedNodes;
+        values[1] = _varNodeToggler;
+        values[2] = _selectedNodeId;
 
         return ((Object) (values));
     }
@@ -70,9 +70,9 @@
     {
         Object values[] = (Object[])state;
         super.restoreState(context, values[0]);
-        _expandedNodes = (HashSet)values[1];
-        setVarNodeToggler((String)values[2]);
-        _selectedNodeId = (String)values[3];
+//        _expandedNodes = (HashSet)values[1];
+        setVarNodeToggler((String)values[1]);
+        _selectedNodeId = (String)values[2];
     }
 
     // see superclass for documentation
@@ -87,37 +87,37 @@
         }
     }
 
-    public void processDecodes(FacesContext context)
-    {
-        super.processDecodes(context);
+//    public void processDecodes(FacesContext context)
+//    {
+//        super.processDecodes(context);
+//
+//        // store the expand/collapse state information in the session (long story)
+//        Map sessionMap = context.getExternalContext().getSessionMap();
+//        sessionMap.put(NODE_STATE_KEY + ":" + getId(), _expandedNodes);
+//    }
 
-        // store the expand/collapse state information in the session (long story)
-        Map sessionMap = context.getExternalContext().getSessionMap();
-        sessionMap.put(NODE_STATE_KEY + ":" + getId(), _expandedNodes);
-    }
+//    public void encodeBegin(FacesContext context)
+//            throws IOException
+//    {
+//        /**
+//         * The expand/collapse state of the nodes is stored in the session in order to ensure that this information
+//         * is preserved across requests where the same tree is reused in a tile (server-side include.)  When using
+//         * the server-side toggle method without this step, the tree would not remember the expand/collapse state.
+//         * Since we didn't think it was appropriate to burden the end user with this information as part of a backing
+//         * bean, it just being stored in the session during encode and retrieved during decode.
+//         */
+//        // restore the expand/collapse state information from the session
+//        Map sessionMap = context.getExternalContext().getSessionMap();
+//        HashSet nodeState = (HashSet)sessionMap.get(NODE_STATE_KEY + ":" + getId());
+//
+//        if (nodeState != null)
+//        {
+//            _expandedNodes = nodeState;
+//        }
+//
+//        super.encodeBegin(context);
+//    }
 
-    public void encodeBegin(FacesContext context)
-            throws IOException
-    {
-        /**
-         * The expand/collapse state of the nodes is stored in the session in order to ensure that this information
-         * is preserved across requests where the same tree is reused in a tile (server-side include.)  When using
-         * the server-side toggle method without this step, the tree would not remember the expand/collapse state.
-         * Since we didn't think it was appropriate to burden the end user with this information as part of a backing
-         * bean, it just being stored in the session during encode and retrieved during decode.
-         */
-        // restore the expand/collapse state information from the session
-        Map sessionMap = context.getExternalContext().getSessionMap();
-        HashSet nodeState = (HashSet)sessionMap.get(NODE_STATE_KEY + ":" + getId());
-
-        if (nodeState != null)
-        {
-            _expandedNodes = nodeState;
-        }
-
-        super.encodeBegin(context);
-    }
-
     /**
      * Gets the expand/collapse control that can be used to handle expand/collapse nodes.  This is only used in server-side
      * mode.  It allows the nagivation controls (if any) to be clickable as well as any commandLinks the user has set up in
@@ -140,30 +140,30 @@
         _expandControl.setAction(actionBinding);
     }
 
-    public String toggleExpanded()
-    {
-        String nodeId = getNodeId();
+//    public void toggleExpanded()
+//    {
+//        String nodeId = getNodeId();
+//
+//        if (_expandedNodes.contains(nodeId))
+//        {
+//            _expandedNodes.remove(nodeId);
+//        }
+//        else
+//        {
+//            _expandedNodes.add(nodeId);
+//        }
+//
+//        return null;
+//    }
 
-        if (_expandedNodes.contains(nodeId))
-        {
-            _expandedNodes.remove(nodeId);
-        }
-        else
-        {
-            _expandedNodes.add(nodeId);
-        }
-
-        return null;
-    }
-
     /**
      * Indicates whether or not the current {@link TreeNode} is expanded.
      * @return boolean
      */
-    public boolean isNodeExpanded()
-    {
-        return (_expandedNodes.contains(getNodeId()) && getNode().getChildCount() > 0);
-    }
+//    public boolean isNodeExpanded()
+//    {
+//        return (_expandedNodes.contains(getNodeId()) && getNode().getChildCount() > 0);
+//    }
 
     protected void processChildNodes(FacesContext context, TreeNode parentNode, int processAction)
     {
Index: src/java/org/apache/myfaces/custom/tree2/UITreeData.java
===================================================================
--- src/java/org/apache/myfaces/custom/tree2/UITreeData.java	(revision 227400)
+++ src/java/org/apache/myfaces/custom/tree2/UITreeData.java	(working copy)
@@ -59,7 +59,7 @@
     private static final int PROCESS_UPDATES = 3;
 
     private TreeModel _model;
-    private TreeNode _value;
+    private Object _value;
     private String _var;
     private String _nodeId;
     private Map _saved = new HashMap();
@@ -84,7 +84,8 @@
     {
         Object values[] = new Object[3];
         values[0] = super.saveState(context);
-        values[1] = _value;
+        //values[1] = _value;
+        values[1] = _model;
         values[2] = _var;
         return ((Object) (values));
     }
@@ -96,7 +97,8 @@
         Object values[] = (Object[]) state;
         super.restoreState(context, values[0]);
 
-        _value = (TreeNode)values[1];
+        //_value = values[1];
+        _model = (TreeModel)values[1];
         _var = (String)values[2];
     }
 
@@ -212,7 +214,7 @@
      *
      * @param value The new value
      */
-    public void setValue(TreeNode value)
+    public void setValue(Object value)
     {
         _model = null;
         _value = value;
@@ -687,4 +689,22 @@
 
         return false;
     }
+
+    /**
+     * Toggle the expanded state of the current node.
+     */    
+    public void toggleExpanded()
+    {
+        getDataModel().toggleExpanded(getNodeId());
+    }
+    
+    /**
+     * Indicates whether or not the current {@link TreeNode} is expanded.
+     * @return boolean
+     */
+    public boolean isNodeExpanded()
+    {
+        return getDataModel().isNodeExpanded(getNodeId());
+    }
+    
 }
Index: src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java
===================================================================
--- src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java	(revision 227400)
+++ src/java/org/apache/myfaces/custom/tree2/TreeModelBase.java	(working copy)
@@ -19,6 +19,7 @@
 
 import java.util.StringTokenizer;
 import java.util.ArrayList;
+import java.util.HashSet;
 
 /**
  * Model class for the tree component.  It provides random access to nodes in a tree
@@ -32,6 +33,7 @@
 {
     private final static String SEPARATOR = String.valueOf(NamingContainer.SEPARATOR_CHAR);
 
+    private HashSet _expandedNodes = new HashSet();
     private TreeNode root;
     private TreeNode currentNode;
 
@@ -150,4 +152,24 @@
 
         return node;
     }
+    
+    // see interface
+    public boolean isNodeExpanded(String nodeId)
+    {
+        return (_expandedNodes.contains(nodeId) && !getNode().isLeaf());
+        //return (_expandedNodes.contains(nodeId) && getNode().getChildCount() > 0);
+    }
+    
+    // see interface
+    public void toggleExpanded(String nodeId)
+    {
+        if (_expandedNodes.contains(nodeId))
+        {
+            _expandedNodes.remove(nodeId);
+        }
+        else
+        {
+            _expandedNodes.add(nodeId);
+        }
+    }
 }
