
[ x:tree ]
■2005/9/13
Hepon
■環境:JSF1.1
MyFaces1.0.9
WindowsXP
ExadelStudioPro3.0.3
■時間があれば後で解説を記述します。
ひとまず画面写真とソースをどうぞ。

★TreeBean.java
package demo;
import org.apache.myfaces.custom.tree.DefaultMutableTreeNode;
import org.apache.myfaces.custom.tree.model.DefaultTreeModel;
public class TreeBean {
private DefaultTreeModel tree;
private DefaultMutableTreeNode treeRoot;
private DefaultMutableTreeNode child01;
private DefaultMutableTreeNode child02;
private DefaultMutableTreeNode child03;
private DefaultMutableTreeNode child01_01;
private DefaultMutableTreeNode child01_02;
private DefaultMutableTreeNode child02_01;
private DefaultMutableTreeNode child02_01_node;
public TreeBean(){
//root
treeRoot = new DefaultMutableTreeNode("ROOT");
child01 = new DefaultMutableTreeNode("分類01");
child02 = new DefaultMutableTreeNode("分類02");
child03 = new DefaultMutableTreeNode("分類03");
treeRoot.insert(child01);
treeRoot.insert(child02);
treeRoot.insert(child03);
//分類01
child01_01 = new DefaultMutableTreeNode("うどん");
child01_02 = new DefaultMutableTreeNode("そば");
child01.insert(child01_01);
child01.insert(child01_02);
//分類02
child02_01 = new DefaultMutableTreeNode("ラーメン");
child02.insert(child02_01);
//ラーメン
child02_01_node = new DefaultMutableTreeNode("醤油ラーメン");
child02_01.insert(child02_01_node);
child02_01_node = new DefaultMutableTreeNode("味噌ラーメン");
child02_01.insert(child02_01_node);
child02_01_node = new DefaultMutableTreeNode("豚骨ラーメン");
child02_01.insert(child02_01_node);
//このtreeをx:treeに与える
tree = new DefaultTreeModel(treeRoot);
}
public DefaultTreeModel getTree() {
return tree;
}
public void setTree(DefaultTreeModel tree) {
this.tree = tree;
}
}
★tree.jsp
<%@ page contentType="text/html;charset=MS932" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.sourceforge.net/tld/myfaces_ext_0_9.tld" prefix="x" %>
<!-- ********************* -->
<HTML>
<HEAD>
<title>x:tree サンプル</title>
</HEAD>
<body bgcolor="white">
<f:view>
<h:form id="form001">
<!-- ********************* -->
<h1><h:outputText value="x:tree サンプル"/></h1>
<h:outputText value="2005/9/13/Tue/Hepon"/><br>
<br>
<!-- ↓ツリー↓ -->
<x:tree id="tree" value="#{TreeBean.tree}"
nodeClass="treenode"
selectedNodeClass="treenodeSelected"
expandRoot="true">
</x:tree>
<!-- ********************* -->
</h:form>
</f:view>
</body>
</HTML>
★index.jsp
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
</head>
<body>
<jsp:forward page="/pages/tree.jsf" />
</body>
</html>
★web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>htc008</display-name>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<filter>
<filter-name>extensionsFilter</filter-name>
<filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>extensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
<!-- Listener, that does all the startup work (configuration, init). -->
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
★faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>TreeBean</managed-bean-name>
<managed-bean-class>demo.TreeBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<lifecycle/>
<application>
<locale-config/>
</application>
<factory/>
</faces-config>