You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/03/20 23:37:46 UTC

svn commit: r158367 [2/2] - in struts/flow/trunk: ./ src/java/ src/java/org/apache/struts/flow/ src/java/org/apache/struts/flow/core/ src/java/org/apache/struts/flow/json/ src/remote-example/ src/remote-example/WEB-INF/

Added: struts/flow/trunk/src/remote-example/clientFlow.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/remote-example/clientFlow.js?view=auto&rev=158367
==============================================================================
--- struts/flow/trunk/src/remote-example/clientFlow.js (added)
+++ struts/flow/trunk/src/remote-example/clientFlow.js Sun Mar 20 14:37:44 2005
@@ -0,0 +1,115 @@
+/* XMLHTTP functions 0.2 */
+/* For all the Railsers out there */
+
+/* Revisions */
+/* 0.1 - 24 Jan 2005 - Written by Peter Cooper (coops) */
+/* 0.2 - 26 Jan 2005 - ixXMLHTTPRequestSupported and success object checking supplied 
+			by Jakob of http://Mentalized.net/ */
+
+/* The licence is simple, use however you want, but leave attribution to any authors
+   listed above, including yourself :-) */
+
+function flowCall(url, func, contid, data) {
+  method = "POST";
+  if (!data) data = null;
+  url = url + "?contid="+contid+"&FlowCall="+func;
+  req = xmlHTTPRequestObject();
+  if (req) {
+	  req.open (method, url, false);
+      json = stringify(data);
+      //alert("sending:"+json);
+	  req.send (json);
+      //alert("response:"+req.responseText);
+	  eval("ret = "+req.responseText);
+      return ret;
+  }
+  return false;
+}
+
+/*function xmlHTTPAsyncRequest(url, method, data, callbackr) {
+  if (!method) method = "GET";
+  if (!data) data = null;
+  req = xmlHTTPRequestObject();
+  if (req) {
+  	eval ('req.onreadystatechange = ' + callbackr + ';');
+	req.open (method, url, true);
+	req.send (data);
+	return req
+  }
+}
+*/
+
+function xmlHTTPRequestObject() {
+	var obj = false;
+	var objectIDs = new Array(
+		"Microsoft.XMLHTTP",
+		"Msxml2.XMLHTTP",
+		"MSXML2.XMLHTTP.3.0",
+		"MSXML2.XMLHTTP.4.0"
+	);
+	var success = false;
+
+	for (i=0; !success && i < objectIDs.length; i++) {
+		try {
+			obj = new ActiveXObject(objectIDs[i]);
+			success = true;
+		} catch (e) { obj = false; }
+	}
+
+	if (!obj)
+		obj = new XMLHttpRequest();
+
+	return obj;
+}
+
+function isXMLHTTPRequestSupported() {
+	return xmlHTTPRequestObject != null;
+}
+
+function stringify(arg) {
+    var i, o, u, v;
+
+    switch (typeof arg) {
+    case 'object':
+        if (arg) {
+            if (arg.constructor == Array) {
+                o = '';
+                for (i = 0; i < arg.length; ++i) {
+                    v = stringify(arg[i]);
+                    if (o) {
+                        o += ',';
+                    }
+                    if (v !== u) {
+                        o += v;
+                    } else {
+                        o += 'null,';
+                    }
+                }
+                return '[' + o + ']';
+            } else if (typeof arg.toString != 'undefined') {
+                o = '';
+                for (i in arg) {
+                    v = stringify(arg[i]);
+                    if (v !== u) {
+                        if (o) {
+                            o += ',';
+                        }
+                        o += stringify(i) + ':' + v;
+                    }
+                }
+                return '{' + o + '}';
+            } else {
+                return;
+            }
+        }
+        return 'null';
+    case 'unknown':
+    case 'undefined':
+    case 'function':
+        return u;
+    case 'string':
+        return '"' + arg.replace(/(["\\])/g, '\\$1') + '"';
+    default:
+        return String(arg);
+    }
+}

Propchange: struts/flow/trunk/src/remote-example/clientFlow.js
------------------------------------------------------------------------------
    svn:executable = *

Added: struts/flow/trunk/src/remote-example/guess.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/remote-example/guess.jsp?view=auto&rev=158367
==============================================================================
--- struts/flow/trunk/src/remote-example/guess.jsp (added)
+++ struts/flow/trunk/src/remote-example/guess.jsp Sun Mar 20 14:37:44 2005
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<html>
+<head>
+  <title>Struts Flow number guessing game</title>
+    <script type="text/javascript">
+  <!--
+var contid = "<%=request.getAttribute("contid")%>";
+function cheat() {
+    result = flowCall("guess.do", "cheat", contid, []);
+    alert("The secret number is "+result.secret);
+}
+    -->
+  </script>
+  <script type="text/javascript" src="clientFlow.js" />
+</head>
+<body>
+
+  <h1>Guess the Number Between 1 and 10</h1>
+  
+  <h2><%= request.getAttribute("hint") %></h2>
+  
+  <h3>You've guessed <%= request.getAttribute("guesses") %> times.</h3>
+  
+  <form method="post" action="guess.do">
+    <input type="hidden" name="contid" value='<%= request.getAttribute("contid") %>' />
+    <input type="text" name="guess"/>
+    <input type="submit"/>
+    <input type="button" onclick="cheat()" value="Cheat" />
+  </form>
+  
+</body>
+</html>
\ No newline at end of file

Propchange: struts/flow/trunk/src/remote-example/guess.jsp
------------------------------------------------------------------------------
    svn:executable = *

Added: struts/flow/trunk/src/remote-example/index.html
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/remote-example/index.html?view=auto&rev=158367
==============================================================================
--- struts/flow/trunk/src/remote-example/index.html (added)
+++ struts/flow/trunk/src/remote-example/index.html Sun Mar 20 14:37:44 2005
@@ -0,0 +1,9 @@
+<html>
+<head>
+  <META HTTP-EQUIV="Refresh" CONTENT="0;URL=./guess.do">
+</head>
+<body>
+  <p>Should be redirected to <a href="guess.do">guess.do</a>
+  </p>
+</body>
+</html>

Propchange: struts/flow/trunk/src/remote-example/index.html
------------------------------------------------------------------------------
    svn:executable = *

Added: struts/flow/trunk/src/remote-example/success.jsp
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/remote-example/success.jsp?view=auto&rev=158367
==============================================================================
--- struts/flow/trunk/src/remote-example/success.jsp (added)
+++ struts/flow/trunk/src/remote-example/success.jsp Sun Mar 20 14:37:44 2005
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<html>
+<head>
+  <title>cocoon flow number guessing game</title>
+</head>
+<body>
+
+  <h1>Success!</h1>
+   
+  <h2>The number was: <%= request.getAttribute("random") %></h2>
+  
+  <h3>It took you <%= request.getAttribute("guesses") %> tries.</h3>
+  
+  <p><a href="guess.do">Play again</a></p>
+  
+</body>
+</html>
\ No newline at end of file

Propchange: struts/flow/trunk/src/remote-example/success.jsp
------------------------------------------------------------------------------
    svn:executable = *



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