Basic Tree | Folder Style Tree | Tree with Html Nodes | Tree with Custom Icons | Menu Styled Tree |
component-family | net.sf.yui4jsf.TreeView |
renderer-type | net.sf.yui4jsf.component.treeview.TreeViewRenderer |
component-class | net.sf.yui4jsf.component.treeview.TreeView |
renderer-class | net.sf.yui4jsf.component.TreeViewRenderer |
tag-class | net.sf.yui4jsf.component.treeview.TreeViewTag |
<yui:treeView widgetId="myWidgetId" value="#{backingBean.treeDataModel}" style="width:220px;..." styleClass="CSSClass" useCustomStyle="true" expandAnim="FADE_IN" collapseAnim="FADE_OUT" onExpand="nodeExpand" onCollapse="nodeCollapse" onItemClick="nodeClicked" lazyLoadListener="#{treeViewLazyLoaderListener}" itemClickListener="#{treeViewItemClickListener}" itemExpandListener="#{treeViewItemExpandListener}" itemCollapseListener="#{treeViewItemCollapseListener}"> </yui:treeView>
<yui:treeView>
Standard Attributes - id, rendered, binding.
widgetId - Use this as the treeview widget's variable name to provide direct access to the yui widget variable name.
styleClass - Style class of the main div element containing the tab view.
useCustomStyle - use your custom style. When set to true, treeview won't include its default style to page. See "Folder Style Tree", "Menu Tree", "Custom Icons in Tree" examples.
expandAnim - Animation type while expanding.
collapseAnim - Animation type while collapsing.
onExpand - JavaScript function name to call when a node expanded. Function gets expanded node as parameter. See "TreeView with Events" sample.
onCollapse - JavaScript function name to call when a node collapsed. Function gets collapsed node as parameter. See "TreeView with Events" sample.
onItemClick - JavaScript function name to call when a node clicked. Function gets clicked node as parameter. See "TreeView with Events" sample.
lazyLoadListener - Listener bean to do server side lazy loading. Implements "TreeViewLazyLoadingListener" interface and returns lazy loaded data as treeview base datamodel("TreeDataModel") when its "processTreeViewLazyLoad" function called with "TreeViewLazyLoadingEvent" param. See "TreeView with ServerSide Events" sample.
itemClickListener - Listener bean handling server side item click events of treeview. Implements "TreeItemClickedListener" interface. "processTreeItemClicked" function of this listener called with "TreeItemClickedEvent" param when a treeview item clicked. See "TreeView with ServerSide Events" sample.
itemExpandListener - Listener bean handling server side item expand events of treeview. Implements "TreeItemExpandedListener" interface. "processTreeItemExpanded" function of this listener called with "TreeItemExpandedEvent" param when a treeview item expanded. See "TreeView with ServerSide Events" sample.
itemCollapseListener - Listener bean handling server side item collapse events of treeview. Implements "TreeItemCollapsedListener" interface. "processTreeItemCollapsed" function of this listener called with "TreeItemCollapsedEvent" param when a treeview item collapsed. See "TreeView with ServerSide Events" sample.
TreeView needs an id and a data model set at minimal. This creates a treeview component with its default style (see "Basic Tree" example).
see "Folder Style Tree", "Menu Tree" or "Custom Icons in Tree" examples.
TreeView component can invoke client side handler functions for "onExpand", "onCollapse", "onItemClick" events. To handle an event, create a javascript function getting the relevant node as parameter and set its name to the proper treeview attribute like below; (see also "TreeView with Events" examples)
//.................. <script type="text/javascript"> function nodeExpand(node) { alert("\"" + node.label + "\"" + " was expanded"); } </script> //.................. <yui:treeView id="treeView1" value="#{treeViewBean.basicTreeDataModel}" onExpand="nodeExpand"> </yui:treeView> //..................
TreeView component also supports lazy loading mode. To make a tree working at lazy mode;
public class TreeViewBean implements TreeViewLazyLoadingListener { public TreeDataModel processTreeViewLazyLoad(TreeViewLazyLoadingEvent event) { // create sample childs for clicked node... Random generator = new Random(); int childCount = generator.nextInt(15) + 1; // create a base tree data model object TreeDataModel childListDataModel = new BaseTreeDataModelImpl(); // ... and add some childs to data model for(int i=1; i<=childCount; i++) { childListDataModel.addNode(new TextNode("c"+i, "dyna child "+i)); } // last; return the resulting data model which includes lazy loaded data return childListDataModel; } }
<yui:treeView id="treeView1" value="#{treeViewBean.lazyTreeDataModel}" lazyLoadListener="#{treeViewBean}"> </yui:treeView>
TreeView component can invoke your server side event handling methods when an item clicked, expanded or collapsed. Since it calls your event handlers by ajax way, full page submitting does not occurs.
To handle treeview events;public class TreeViewBean implements TreeItemClickedListener { public void processTreeItemClicked(TreeItemClickedEvent event) { // your item clicked event handling code... } }
public class TreeViewBean implements TreeItemExpandedListener { public void processTreeItemExpanded(TreeItemExpandedEvent event) { // your item expanded event handling code... } }
public class TreeViewBean implements TreeItemCollapsedListener { public void processTreeItemCollapsed(TreeItemCollapsedEvent event) { // your item collapsed event handling code... } }
<yui:treeView id="treeView1" value="#{treeViewBean.sampleTreeDataModel}" itemClickListener="#{treeViewBean}" itemExpandListener="#{treeViewBean}" itemCollapseListener="#{treeViewBean}"> </yui:treeView>