没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > granizo |
granizo
|
0 | 0 | 8 |
贡献者 | 讨论 | 代码提交 |
Introductiongranizo is custom JSP tag library that allows you to traverse an arbitrary tree structure.
granizo is very flexible on accepting input as it does not require a specific type for its input attribute and can transform any object provided to a tree structure.
UsagePut the jar in the classpath, for example /WEB-INF/lib/ Add a reference to the custom tag at the top of the JSP file <%@taglib uri="http://code.google.com/granizo" prefix="granizo"%>
You can now use granizo in your JSP page
Current element is ${status.element} at level ${status.level}
Tag atributes
Name Required Description tree true The root element(s) of the tree to iterate over. This can be any Java object. connectMethod true The method that will be invoked on each tree element to retrieve the child nodes. var false Name of the exported variable. The exported object is of type org.granizo.treetag.TreeIteratorStatus
SampleUse case: show an organigram of a company where each employee can have 0, 1 or multiple subordinates.
Employee class
package org.granizo.test;
import java.util.List;
public class Employee {
private List subordinates;
private String name;
public Employee(String name) {
this.name = name;
}
public List getSubordinates() {
return subordinates;
}
public void setSubordinates(List subordinates) {
this.subordinates = subordinates;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}organigram.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="org.granizo.test.Employee"%>
<%@page import="java.util.Arrays"%>
<%taglib uri="http://code.google.com/p/granizo" prefix="granizo"%>
taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
Organizational chart
<%
// Setting up data
Employee jim = new Employee("Jim");
Employee tom = new Employee("Tom");
Employee marc = new Employee("Marc");
Employee dave = new Employee("Dave");
Employee kelly = new Employee("Kelly");
Employee bob = new Employee("Bob");
// Build the tree
jim.setSubordinates(Arrays.asList(tom, marc));
tom.setSubordinates(Arrays.asList(dave, kelly));
kelly.setSubordinates(Arrays.asList(bob));
// Put the root element into page context
pageContext.setAttribute("orgTree", jim);
%>
Here is the organigram:
${status.element.name}
Here is the output:
Jim Tom Dave Kelly Bob Marc