You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by pl...@apache.org on 2006/04/25 08:25:29 UTC

svn commit: r396783 - in /incubator/webwork2/webapps/showcase/src/main: java/org/apache/struts/action2/showcase/ajax/tree/ webapp/WEB-INF/classes/ webapp/ajax/tree/

Author: plightbo
Date: Mon Apr 24 23:25:27 2006
New Revision: 396783

URL: http://svn.apache.org/viewcvs?rev=396783&view=rev
Log:
simple tree widget

Added:
    incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/
    incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Category.java
    incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/GetCategory.java
    incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Toggle.java
    incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/
    incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/getCategory.jsp
    incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/partialChunkHeader.jsp
    incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/toggle.jsp
    incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/tree.jsp
Modified:
    incubator/webwork2/webapps/showcase/src/main/webapp/WEB-INF/classes/xwork-ajax.xml

Added: incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Category.java
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Category.java?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Category.java (added)
+++ incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Category.java Mon Apr 24 23:25:27 2006
@@ -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;
+    }
+}

Added: incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/GetCategory.java
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/GetCategory.java?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/GetCategory.java (added)
+++ incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/GetCategory.java Mon Apr 24 23:25:27 2006
@@ -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;
+    }
+}

Added: incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Toggle.java
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Toggle.java?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Toggle.java (added)
+++ incubator/webwork2/webapps/showcase/src/main/java/org/apache/struts/action2/showcase/ajax/tree/Toggle.java Mon Apr 24 23:25:27 2006
@@ -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;
+    }
+}

Modified: incubator/webwork2/webapps/showcase/src/main/webapp/WEB-INF/classes/xwork-ajax.xml
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/webapp/WEB-INF/classes/xwork-ajax.xml?rev=396783&r1=396782&r2=396783&view=diff
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/webapp/WEB-INF/classes/xwork-ajax.xml (original)
+++ incubator/webwork2/webapps/showcase/src/main/webapp/WEB-INF/classes/xwork-ajax.xml Mon Apr 24 23:25:27 2006
@@ -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>

Added: incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/getCategory.jsp
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/getCategory.jsp?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/getCategory.jsp (added)
+++ incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/getCategory.jsp Mon Apr 24 23:25:27 2006
@@ -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>
\ No newline at end of file

Added: incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/partialChunkHeader.jsp
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/partialChunkHeader.jsp?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/partialChunkHeader.jsp (added)
+++ incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/partialChunkHeader.jsp Mon Apr 24 23:25:27 2006
@@ -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
+%>

Added: incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/toggle.jsp
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/toggle.jsp?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/toggle.jsp (added)
+++ incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/toggle.jsp Mon Apr 24 23:25:27 2006
@@ -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 = "";
+}

Added: incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/tree.jsp
URL: http://svn.apache.org/viewcvs/incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/tree.jsp?rev=396783&view=auto
==============================================================================
--- incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/tree.jsp (added)
+++ incubator/webwork2/webapps/showcase/src/main/webapp/ajax/tree/tree.jsp Mon Apr 24 23:25:27 2006
@@ -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>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org