You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2006/01/21 18:13:09 UTC

[Myfaces Wiki] Update of "Tree2" by jtmille3

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by jtmille3:
http://wiki.apache.org/myfaces/Tree2

The comment on the change is:
Alternative Tree2 Lazy Loading Method

------------------------------------------------------------------------------
  See http://wiki.apache.org/myfaces/How_JSF_State_Management_Works
  
  
+ '''Alternative Tree2 Lazy Loading Method...by jtmille3'''
+ 
+ The differences between my implementation and the one above is that my lazy loading happens in an extended TreeNode.  Whereas the implementation above performs the lazy loading in the backing bean.  With my example I can also leave the navigation buttons on the tree and leave the tree pretty much as is.  Except for the extended TreeNode most of my code is an adaptation of the Tree2 example from the Apache MyFaces project.
+ 
+ '''JSP Code Snippet'''
+ The clientSideToggle must remain false for my example.  The client side tree will retrieve all nodes and won't work for this specific example.
+ {{{
+ <t:tree2 id="serverTree" value="#{treeBacker.treeModel}" var="node" varNodeToggler="t" preserveToggle="false" clientSideToggle="false">
+ 		<f:facet name="folder">
+ 			<h:panelGroup>
+ 				<t:graphicImage value="/images/yellow-folder-open.png" rendered="#{t.nodeExpanded}" border="0" />
+ 				<t:graphicImage value="/images/yellow-folder-closed.png" rendered="#{!t.nodeExpanded}" border="0" />
+ 				<h:outputText value="#{node.description}" styleClass="nodeFolder" />
+ 			</h:panelGroup>
+ 		</f:facet>
+ 		<f:facet name="document">
+ 			<h:panelGroup>
+ 				<h:commandLink immediate="true" styleClass="#{t.nodeSelected ? 'documentSelected':'document'}" action="#{treeBacker.selectedNode}" actionListener="#{t.setNodeSelected}">
+ 					<t:graphicImage value="/images/document.png" border="0" />
+ 					<h:outputText value="#{node.description}" />
+ 					<f:param name="docNum" value="#{node.identifier}" />
+ 				</h:commandLink>
+ 			</h:panelGroup>
+ 		</f:facet>
+ 	</t:tree2>
+ }}}
+ 
+ '''{{{TreeBacker.java}}}''' - managed bean
+ 
+ {{{
+ public final class TreeBacker extends Object {
+ 
+ 	private TreeModelBase _treeModel;
+ 
+ 	private String selectedNode;
+ 
+ 	public TreeBacker() {
+              // Initialize the tree with the root node
+ 		TreeNode treeData = new LazyTreeNode("folder", "1", "1", false);
+ 		_treeModel = new TreeModelBase(treeData);
+ 	}
+ 
+ 	public TreeModel getTreeModel() {
+ 		return _treeModel;
+ 	}
+ 
+ 	public void selectedNode(ActionEvent event) {
+ 		this.selectedNode = this.getTreeModel().getNode().getDescription();
+ 	}
+ 
+ 	public String getSelectedNode() {
+ 		return selectedNode;
+ 	}
+ }
+ }}}
+ 
+ '''{{{LazyTreeNode.java}}}'''
+ 
+ {{{
+ public class LazyTreeNode extends TreeNodeBase {
+ 
+ 	private static final long serialVersionUID = -6870203633601493362L;
+ 
+ 	public LazyTreeNode() {
+ 	}
+ 
+ 	public LazyTreeNode(String type, String description, boolean leaf) {
+ 		super(type, description, leaf);
+ 	}
+ 
+ 	public LazyTreeNode(String type, String description, String identifier, boolean leaf) {
+ 		super(type, description, identifier, leaf);
+ 	}
+ 
+ 	public List getChildren() {
+              // if there are no children, try and retrieve them
+ 		if (super.getChildren().size() == 0) {
+                    // create dummy tree nodes for example
+                    int id = Integer.parseInt(getIdentifier());
+ 			for(int i = 0; i < id; i++) {
+                        super.getChilren().add(new LazyTreeNode("document","" + id, "" + id,false);
+                    }
+ 		}
+ 
+ 		return super.getChildren();
+ 	}
+ }
+ }}}
+ 
  == Controlling Which Nodes are Expanded from the Backing Bean ==
  ''TODO''