tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Excerpt Include
ajax common header
nopaneltrue

Description

Wiki Markup
{snippet:id=javadoc|javadoc=true|url=org.apache.struts2.components.Tree}

Quick Example

This example describes basic usage of the <s:tree.../> tag showing both the model behind the tree and the JSP fragment that uses it. This section of the documentation is a work-in-progress; more to follow.

Code Block
titleBacking Model

/**
 * In this example it is assumed that the backing POJO is a tree-like structure
 * consisting of same-type elements, roughly like the following, with getters
 * and setters not shown for clarity.
 *
 * This could be, say, a Hibernate/etc. POJO stored in a database and loaded lazily, etc.
 *
 * TODO Determine allowable collection types; I know for a fact Set works.
 */
public class TreeModel {
    private Long _id;                 // Node's ID.
    private String _name;             // Node's name property.
    private Set<TreeModel> _children; // Node's children.
}
Code Block
titleAction

/**
 * Fragment of Action class showing the minimum necessary to support the
 * following JSP code. Getters, setters, functionality not shown.
 */
public class ShowTreeAction {
    private TreeModel _rootNode;      // Top-level tree node.
}

...


<!-- 
  - @attrib rootNode 
  -             OGNL value holding top-level tree node.
  - @attrib childCollectionProperty 
  -             Property of rootNode containing child nodes.
  - @attrib nodeIdProperty
  -             Property of each node containing "value" of node, like an ID.
  - @attrib nodeTitleProperty
  -             Property of each node containing tree label text.
  -->
<s:tree theme="ajax"
        rootNode="%{rootNode}"
        childCollectionProperty="children"
        nodeIdProperty="id"
        nodeTitleProperty="name">
</s:tree>

Parameters

/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java}

Parameters

Wiki Markup
{snippet:id=tagattributes|javadoc=false|url=struts2-tags/ajax/tree.html}

Examples

Static tree:

Wiki Markup
{snippet:id=example1|lang=xml|javadoc=true|url=struts2/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java}

Dynamic tree (rendered on the server):

Wiki Markup
{snippet:id=tagattributesexample2|lang=xml|javadoc=falsetrue|url=struts2-tags/tree.html}

...

/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java}

Dynamic tree loaded with AJAX (one request is made for each node):

Wiki Markup
{snippet:id=exampleexample3|lang=xml|javadoc=true|url=org.apache.struts2.components.Treestruts2/plugins/dojo/src/main/java/org/apache/struts2/dojo/components/Tree.java}