Commits

Anonymous committed db38993

WW-1491
Add an example for DWR webwork integration

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2990573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (9)

webapps/showcase/src/java/com/opensymphony/webwork/showcase/dwr/WordCheckAction.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.showcase.dwr;
+
+import com.opensymphony.xwork.ActionSupport;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public class WordCheckAction extends ActionSupport {
+
+
+    private List possibleWords = new ArrayList();
+
+    private String wordToCheckFor = "";
+
+    public void setWordToCheckFor(String wordToCheckFor) {
+        this.wordToCheckFor = wordToCheckFor;
+    }
+
+    public String getWordToCheckFor() {
+        return wordToCheckFor;
+    }
+
+    public String getMsg() {
+        return "testing 1 2 3";
+    }
+
+
+    public String[] getPossibleWords() {
+        return (String[]) possibleWords.toArray(new String[0]);
+    }
+
+
+    public String execute() throws Exception {
+        List words = WordList.getInstance().getAllWords();
+        for (Iterator i = words.iterator(); i.hasNext(); ) {
+            String word = (String) i.next();
+            if (word.indexOf(wordToCheckFor) >= 0) {
+                possibleWords.add(word);
+            }
+        }
+        return SUCCESS;
+    }
+}

webapps/showcase/src/java/com/opensymphony/webwork/showcase/dwr/WordList.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.showcase.dwr;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public class WordList {
+
+    private List words = new ArrayList() {
+        {
+            add("ax");
+            add("air");
+            add("ear");
+            add("ace");
+            add("add");
+            add("age");
+            add("ago");
+            add("aid");
+            add("aim");
+            add("all");
+            add("any");
+            add("ape");
+            add("arc");
+            add("arm");
+            add("art");
+            add("ass");
+            add("awe");
+            add("eat");
+            add("era");
+            add("oaf");
+            add("bar");
+            add("bay");
+            add("car");
+            add("day");
+            add("far");
+            add("gay");
+            add("jar");
+            add("jaw");
+            add("law");
+            add("lay");
+            add("mar");
+            add("par");
+            add("paw");
+            add("pay");
+            add("raw");
+            add("ray");
+        }
+    };
+
+
+    private static WordList wordList;
+
+    private WordList() {}
+
+    public static WordList getInstance() {
+        if (wordList == null) {
+            wordList = new WordList();
+        }
+        return wordList;
+    }
+
+    public List getAllWords() {
+        return words;
+    }
+}

webapps/showcase/src/java/com/opensymphony/webwork/showcase/dwr/WordListAction.java

+/*
+ * Copyright (c) 2002-2007 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.showcase.dwr;
+
+import com.opensymphony.xwork.ActionSupport;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public class WordListAction extends ActionSupport {
+
+    public List getAllWords() {
+        return WordList.getInstance().getAllWords();
+    }
+
+
+    public String execute() throws Exception {
+        return SUCCESS;
+    }
+}

webapps/showcase/src/webapp/WEB-INF/classes/xwork-dwr.xml

+<!DOCTYPE xwork PUBLIC
+        "-//OpenSymphony Group//XWork 1.1.2//EN"
+        "http://www.opensymphony.com/xwork/xwork-1.1.2.dtd">
+
+<xwork>
+    <package name="webwork_dwr" extends="webwork-default" namespace="/webwork_dwr">
+        <action name="index">
+            <result>/webwork_dwr/wordCheck.jsp</result>
+        </action>
+
+        <action name="checkWord" class="com.opensymphony.webwork.showcase.dwr.WordCheckAction">
+        </action>
+
+        <action name="wordList" class="com.opensymphony.webwork.showcase.dwr.WordListAction">
+            <result>/webwork_dwr/wordList.jsp</result>
+        </action>
+    </package>
+</xwork>
+
+        

webapps/showcase/src/webapp/WEB-INF/classes/xwork.xml

     
     <include file="config-browser.xml"/>
 
-	<include file="xwork-messageStore.xml" />
+    <include file="xwork-dwr.xml" />
+
+    <include file="xwork-messageStore.xml" />
 
     <include file="xwork-continuations.xml"/>
 

webapps/showcase/src/webapp/WEB-INF/dwr.xml

 <?xml version="1.0" encoding="UTF-8"?>
 
 <!-- START SNIPPET: dwr -->
-<!DOCTYPE dwr PUBLIC 
-	"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" 
-	"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
+<!DOCTYPE dwr PUBLIC
+        "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
+        "http://getahead.org/dwr//dwr20.dtd">
 
 <dwr>
     <allow>
             <param name="class" value="com.opensymphony.webwork.validators.DWRValidator"/>
         </create>
         <convert converter="bean" match="com.opensymphony.xwork.ValidationAwareSupport"/>
+
+        <create creator="new" javascript="dwraction">
+            <param name="class" value="org.directwebremoting.webwork.DWRAction" />
+        </create>
+        <convert converter="bean" match="org.directwebremoting.webwork.ActionDefinition"/>
+        <convert converter="bean" match="org.directwebremoting.webwork.AjaxResult" />
+        <convert converter="bean" match="com.opensymphony.xwork.ActionSupport" />
     </allow>
 
     <signatures>
         <![CDATA[
         import java.util.Map;
         import com.opensymphony.webwork.validators.DWRValidator;
+        import org.directwebremoting.webwork.ActionDefinition;
+        import org.directwebremoting.webwork.DWRAction;
+        import javax.servlet.http.HttpServletRequest;
+        import javax.servlet.http.HttpServletResponse;
+        import javax.servlet.ServletContext;
 
         DWRValidator.doPost(String, String, Map<String, String>);
+        DWRAction.execute(ActionDefinition, Map<String, String>, HttpServletRequest, HttpServletResponse, ServletContext);
         ]]>
     </signatures>
+    
 </dwr>
 <!-- END SNIPPET: dwr -->

webapps/showcase/src/webapp/WEB-INF/web.xml

 
     <servlet>
         <servlet-name>dwr</servlet-name>
-        <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
+        <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
         <init-param>
             <param-name>debug</param-name>
             <param-value>true</param-value>
         </init-param>
+        <init-param>
+            <param-name>org.directwebremoting.extend.AccessControl</param-name>
+            <param-value>com.opensymphony.webwork.dwr.WebWorkDwrAccessControl</param-value>
+        </init-param>
     </servlet>
 
     <servlet-mapping>

webapps/showcase/src/webapp/webwork_dwr/wordCheck.jsp

+<%--
+  Created by IntelliJ IDEA.
+  User: tmjee
+  Date: Dec 15, 2007
+  Time: 9:37:56 AM
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@taglib prefix="ww" uri="/webwork" %>
+<html>
+  <head>
+      <title>Word Check</title>
+      <ww:head theme="ajax" />
+
+      <script src='<ww:url value="/dwr/interface/dwraction.js" />'></script>
+      <script src='<ww:url value="/dwr/engine.js" />'></script>
+      <script src='<ww:url value="/dwr/util.js" />'></script>
+
+      <script type="text/javascript">
+          dojo.addOnLoad(function() {
+              dojo.event.connect(dojo.byId("word"), "onkeyup", function() {
+                var text = dojo.byId('word').value;
+                dwraction.execute(
+                    {
+                        action: 'checkWord',
+                        namespace: '/webwork_dwr',
+                        executeResult: false
+                    },
+                    {
+                        wordToCheckFor: text
+                    },
+                    function(ajaxResult) {
+                        var possibleWords = ajaxResult.data.possibleWords;
+                        var msg;
+                        if (possibleWords.length > 0) {
+                            msg = "Are you looking for ";
+                            for (var a=0; a<possibleWords.length; a++) {
+                                msg = msg +"<br/>"+possibleWords[a];    
+                            }
+                        }
+                        else {
+                            msg = "Sorry, cannot locate your words";
+                        }
+                        dojo.byId("message").innerHTML = msg;
+                    }
+                );
+              });
+              dojo.event.connect(dojo.byId("wordListButton"), "onclick", function() {
+                dwraction.execute(
+                    {
+                        action: 'wordList',
+                        namespace: '/webwork_dwr',
+                        executeResult: true
+                    },
+                    {},
+                    function(ajaxResult) {
+                        dojo.byId("wordList").innerHTML = ajaxResult.text;
+                    }
+                );
+              });
+
+              dojo.event.connect(dojo.byId("clearListButton"), "onclick", function() {
+                  dojo.byId("wordList").innerHTML = "";
+              });
+          });
+      </script>
+  </head>
+  <body>
+
+     <h1>Word Check</h1>
+     <input id="word" type="text" />
+     <input id="wordListButton" type="button" value="List All Word" />
+     <input id="clearListButton" type="button" value="Hide Word List" />
+     <div>
+         <div id="message" style="float:left">
+
+         </div>
+         <div id="wordList" style="float:left">
+
+         </div>
+     </div>
+  </body>
+</html>

webapps/showcase/src/webapp/webwork_dwr/wordList.jsp

+<%--
+  Created by IntelliJ IDEA.
+  User: tmjee
+  Date: Dec 15, 2007
+  Time: 9:35:05 AM
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@taglib prefix="ww" uri="/webwork" %>
+
+<h4>Word List</h4>
+<ul>
+<ww:iterator id="currentWord" value="%{allWords}">
+    <li>
+        <ww:property value="%{#currentWord}" />
+    </li>
+</ww:iterator>
+</ul>