mirror of
https://github.com/apache/struts.git
synced 2026-08-31 11:24:28 +00:00
simple tree widget
git-svn-id: https://svn.apache.org/repos/asf/incubator/webwork2@396783 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+87
@@ -0,0 +1,87 @@
|
||||
package org.apache.struts.action2.showcase.ajax.tree;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:plightbo@gmail.com">Patrick Lightbody</a>
|
||||
*/
|
||||
public class Category {
|
||||
private static Map<Long, Category> catMap = new HashMap<Long, Category>();
|
||||
|
||||
static {
|
||||
new Category(1, "Root",
|
||||
new Category(2, "Java",
|
||||
new Category(3, "Web Frameworks",
|
||||
new Category(4, "WebWork"),
|
||||
new Category(5, "Struts Action"),
|
||||
new Category(6, "Struts Shale"),
|
||||
new Category(7, "Stripes"),
|
||||
new Category(8, "Rife")),
|
||||
new Category(9, "Persistence",
|
||||
new Category(10, "iBatis"),
|
||||
new Category(11, "Hibernate"),
|
||||
new Category(12, "JDO"),
|
||||
new Category(13, "JDBC"))),
|
||||
new Category(14, "JavaScript",
|
||||
new Category(15, "Dojo"),
|
||||
new Category(16, "Prototype"),
|
||||
new Category(17, "Scriptaculous"),
|
||||
new Category(18, "OpenRico"),
|
||||
new Category(19, "DWR")));
|
||||
}
|
||||
|
||||
public static Category getById(long id) {
|
||||
return catMap.get(id);
|
||||
}
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
private List<Category> children;
|
||||
private boolean toggle;
|
||||
|
||||
public Category(long id, String name, Category... children) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.children = new ArrayList<Category>();
|
||||
for (Category child : children) {
|
||||
this.children.add(child);
|
||||
}
|
||||
|
||||
catMap.put(id, this);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Category> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Category> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
public boolean isToggle() {
|
||||
return toggle;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package org.apache.struts.action2.showcase.ajax.tree;
|
||||
|
||||
import com.opensymphony.xwork.ActionSupport;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:plightbo@gmail.com">Patrick Lightbody</a>
|
||||
*/
|
||||
public class GetCategory extends ActionSupport {
|
||||
private long catId;
|
||||
private Category category;
|
||||
|
||||
public String execute() throws Exception {
|
||||
if (catId < 1) {
|
||||
// force the root
|
||||
catId = 1;
|
||||
}
|
||||
|
||||
category = Category.getById(catId);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setCatId(long catId) {
|
||||
this.catId = catId;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package org.apache.struts.action2.showcase.ajax.tree;
|
||||
|
||||
import com.opensymphony.xwork.ActionSupport;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:plightbo@gmail.com">Patrick Lightbody</a>
|
||||
*/
|
||||
public class Toggle extends GetCategory {
|
||||
public String execute() throws Exception {
|
||||
super.execute();
|
||||
|
||||
getCategory().toggle();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -5,27 +5,39 @@
|
||||
|
||||
<package name="ajax" extends="struts-default">
|
||||
<action name="AjaxTest" class="org.apache.struts.action2.showcase.ajax.AjaxTestAction">
|
||||
<result name="success">/ajax/AjaxResult.jsp</result>
|
||||
<result>/ajax/AjaxResult.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="AjaxRemoteLink" class="org.apache.struts.action2.showcase.ajax.AjaxTestAction">
|
||||
<result name="success">/ajax/AjaxResult2.js</result>
|
||||
<result>/ajax/AjaxResult2.js</result>
|
||||
</action>
|
||||
|
||||
<action name="AjaxRemoteForm" class="org.apache.struts.action2.showcase.ajax.AjaxTestAction">
|
||||
<result name="success">/ajax/AjaxResult3.jsp</result>
|
||||
<result>/ajax/AjaxResult3.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Test1" class="com.opensymphony.xwork.ActionSupport">
|
||||
<result name="success">/ajax/remoteforms/test2.jsp</result>
|
||||
<action name="Test1">
|
||||
<result>/ajax/remoteforms/test2.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Test2" class="com.opensymphony.xwork.ActionSupport">
|
||||
<result name="success">/ajax/remoteforms/test3.jsp</result>
|
||||
<action name="Test2">
|
||||
<result>/ajax/remoteforms/test3.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="Test3" class="com.opensymphony.xwork.ActionSupport">
|
||||
<result name="success">/ajax/testjs.jsp</result>
|
||||
<action name="Test3">
|
||||
<result>/ajax/testjs.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="tree">
|
||||
<result>/ajax/tree/tree.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="getCategory" class="org.apache.struts.action2.showcase.ajax.tree.GetCategory">
|
||||
<result>/ajax/tree/getCategory.jsp</result>
|
||||
</action>
|
||||
|
||||
<action name="toggle" class="org.apache.struts.action2.showcase.ajax.tree.Toggle">
|
||||
<result>/ajax/tree/toggle.jsp</result>
|
||||
</action>
|
||||
</package>
|
||||
</xwork>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<%@ taglib prefix="saf" uri="/struts-action" %>
|
||||
<%@include file="partialChunkHeader.jsp"%>
|
||||
<ul>
|
||||
<saf:iterator value="category.children">
|
||||
<li>
|
||||
<saf:if test="children.size() > 0">
|
||||
<saf:a theme="ajax" href="toggle.action?catId=%{id}">+</saf:a>
|
||||
</saf:if>
|
||||
<saf:property value="name"/>
|
||||
</li>
|
||||
<saf:if test="toggle">
|
||||
<saf:set name="display" value="'none'"/>
|
||||
</saf:if>
|
||||
<saf:else>
|
||||
<saf:set name="display" value="''"/>
|
||||
</saf:else>
|
||||
|
||||
<saf:div theme="ajax"
|
||||
id="children_%{id}"
|
||||
cssStyle="display: %{display}"
|
||||
href="getCategory.action?catId=%{id}"
|
||||
listenTopics="children_%{id}"/>
|
||||
</saf:iterator>
|
||||
</ul>
|
||||
@@ -0,0 +1,6 @@
|
||||
<%
|
||||
request.setAttribute("decorator", "none");
|
||||
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
|
||||
response.setHeader("Pragma","no-cache"); //HTTP 1.0
|
||||
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
|
||||
%>
|
||||
@@ -0,0 +1,12 @@
|
||||
<%@ taglib prefix="saf" uri="/struts-action" %>
|
||||
<%@include file="partialChunkHeader.jsp"%>
|
||||
<%
|
||||
response.setContentType("text/javascript");
|
||||
%>
|
||||
dojo.event.topic.publish("children_<saf:property value="category.id"/>");
|
||||
var d = document.getElementById("children_<saf:property value="category.id"/>");
|
||||
if (d.style.display != "none") {
|
||||
d.style.display = "none";
|
||||
} else {
|
||||
d.style.display = "";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<%@ taglib prefix="saf" uri="/struts-action" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Tree</title>
|
||||
<saf:head theme="ajax"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<saf:action name="getCategory" executeResult="true"/>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user