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/11/27 20:21:16 UTC

svn commit: r349281 - in /struts/flow/trunk/src/examples/WEB-INF: guess/numberguess.js remote/numberguess.js templates/guess.jt templates/numberguess.js

Author: mrdon
Date: Sun Nov 27 11:21:13 2005
New Revision: 349281

URL: http://svn.apache.org/viewcvs?rev=349281&view=rev
Log:
Fixed template example, modified other guess examples to only create
continuations when necessary

Modified:
    struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js
    struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js
    struts/flow/trunk/src/examples/WEB-INF/templates/guess.jt
    struts/flow/trunk/src/examples/WEB-INF/templates/numberguess.js

Modified: struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js?rev=349281&r1=349280&r2=349281&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js (original)
+++ struts/flow/trunk/src/examples/WEB-INF/guess/numberguess.js Sun Nov 27 11:21:13 2005
@@ -30,7 +30,7 @@
   }
 
   // send success page to user
-  flow.forwardAndWait("success", 
+  flow.forward("success", 
      {"random"  : random, 
       "guess"   : guess, 
       "guesses" : guesses} );

Modified: struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js?rev=349281&r1=349280&r2=349281&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js (original)
+++ struts/flow/trunk/src/examples/WEB-INF/remote/numberguess.js Sun Nov 27 11:21:13 2005
@@ -13,8 +13,7 @@
     // can be called remotely.
     flow.forwardAndWait("failure", 
        { "hint"    : hint,
-         "guesses" : guesses},
-       ["cheat"]);
+         "guesses" : guesses});
 
     print("processing a user guess "+struts.param.guess);
     // process user's guess
@@ -35,7 +34,7 @@
   }
 
   // send success page to user
-  flow.forwardAndWait("success", 
+  flow.forward("success", 
      {"random"  : random, 
       "guess"   : guess, 
       "guesses" : guesses} );

Modified: struts/flow/trunk/src/examples/WEB-INF/templates/guess.jt
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/templates/guess.jt?rev=349281&r1=349280&r2=349281&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/templates/guess.jt (original)
+++ struts/flow/trunk/src/examples/WEB-INF/templates/guess.jt Sun Nov 27 11:21:13 2005
@@ -4,25 +4,28 @@
   <title>Struts Flow number guessing game</title>
     <script type="text/javascript">
   <!--
-function init() {
-    this.contid = "${contid}";
-    this.client = new ClientFlow("guess.do");
-}   
 function cheat() {
     hint = document.getElementById("hint");
-    result = client.call("cheat", contid);
-    req = client.xmlHTTPRequestObject();
-    if (req) {
-      req.open ("GET", "cheat.jt", false);
-      req.send (json);
-      hint.innerHTML = req.responseText.process(result);
-    }
-    contid = result.contid;
+    
+    dojo.io.bind({
+        url:  "guess.do?FlowCall=cheat",
+        type: "text/javascript",
+        load: function(type, data, evt) {
+            eval("data = "+data);
+            dojo.io.bind({
+                url:  "cheat.jt",
+                type: "text/plain",
+                load: function(type, temp, evt) {
+                    hint.innerHTML = temp.process(data);
+                }
+            });
+        }
+    });
 }
     -->
   </script>
-  <script type="text/javascript" src="clientFlow.js" />
-  <script type="text/javascript" src="template.js" />
+  <script type="text/javascript" src="../remote/dojo-io.js"></script>
+  <script type="text/javascript" src="template.js"></script>
 </head>
 <body onload="init()">
 

Modified: struts/flow/trunk/src/examples/WEB-INF/templates/numberguess.js
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/templates/numberguess.js?rev=349281&r1=349280&r2=349281&view=diff
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/templates/numberguess.js (original)
+++ struts/flow/trunk/src/examples/WEB-INF/templates/numberguess.js Sun Nov 27 11:21:13 2005
@@ -13,10 +13,9 @@
 
     // send guess page to user and wait for response.  Specify only cheat() 
     // can be called remotely.
-    forwardAndWait("guess", 
+    renderTemplateAndWait("guess", 
        { "hint"    : hint,
-         "guesses" : guesses},
-       ["cheat"]);
+         "guesses" : guesses});
 
     // process user's guess
     var guess = parseInt( struts.param.guess );
@@ -36,7 +35,7 @@
   }
 
   // send success page to user
-  forwardAndWait("success", 
+  renderTemplate("success", 
      {"random"  : random, 
       "guess"   : guess, 
       "guesses" : guesses} );
@@ -47,37 +46,24 @@
     return {"secret":random, "guesses":guesses};
 }
 
-// This function intercepts the forward back to Struts and renders the content
-// directly using Javascript Templates
-function renderTemplate(page, bizdata) { 
-   // if rpc call, use old forward, otherwise use template
-   if (page == "n/a") {
-       return _oldForwardAndWait(page, bizdata);
-   } else {
-       var k = new Continuation();
-       
-       // Use default ttl value from continuation manager
-       var timeToLive = 0;
-       var kont = new WebContinuation(flow, k, lastContinuation, timeToLive);
-       
-       bizdata.contid = kont.id;
-       res = flow.context.response;
-       stream = struts.servletContext.getResourceAsStream("/WEB-INF/templates/"+page+".jt");
-       if (stream != null) {
-           text = new String(stream.getText());
-           html = text.process(bizdata);
-           res.writer.print(html);
-           res.writer.close();
-       } else {
-           res.sendError(res.SC_INTERNAL_SERVER_ERROR, "Unable to find page "+page);
-       }    
-       
-       suicide();
-       return kont;
-   }
+// This function renders the content directly using Javascript Templates
+function renderTemplateAndWait(page, bizdata, ttl) { 
+   var cont = new FOM_WebContinuation(new Continuation(), flow.continuation, ttl);
+   bizdata.contid = cont.id;
+   renderTemplate(page, bizdata);
+   flow.forward(null, bizdata, cont);
+   FOM_Flow.suicide();
 }
 
-// Replace old forward method with ours, but keep a reference to it so we can
-// call it for remote flow responses
-this._oldForwardAndWait = _forwardAndWait;
-this._forwardAndWait = renderTemplate;
+function renderTemplate(page, bizdata) {
+   var res = flow.context.response;
+   var stream = struts.servletContext.getResourceAsStream("/WEB-INF/templates/"+page+".jt");
+   if (stream != null) {
+       var text = new String(stream.getText());
+       var html = text.process(bizdata);
+       res.writer.print(html);
+       res.writer.close();
+   } else {
+       res.sendError(res.SC_INTERNAL_SERVER_ERROR, "Unable to find page "+page);
+   }  
+}



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