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 2006/01/22 02:32:03 UTC

svn commit: r371161 - in /struts/flow/trunk: project.xml xdocs/guess-example.xml xdocs/index.xml xdocs/remote-example.xml xdocs/templates-example.xml xdocs/wizard-example.xml

Author: mrdon
Date: Sat Jan 21 17:32:01 2006
New Revision: 371161

URL: http://svn.apache.org/viewcvs?rev=371161&view=rev
Log:
Updated documentation, fixed jar not having correct files

Modified:
    struts/flow/trunk/project.xml
    struts/flow/trunk/xdocs/guess-example.xml
    struts/flow/trunk/xdocs/index.xml
    struts/flow/trunk/xdocs/remote-example.xml
    struts/flow/trunk/xdocs/templates-example.xml
    struts/flow/trunk/xdocs/wizard-example.xml

Modified: struts/flow/trunk/project.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/project.xml?rev=371161&r1=371160&r2=371161&view=diff
==============================================================================
--- struts/flow/trunk/project.xml (original)
+++ struts/flow/trunk/project.xml Sat Jan 21 17:32:01 2006
@@ -237,6 +237,8 @@
         <directory>${basedir}/src/java</directory>
         <includes>
           <include>**/*.template</include>
+          <include>**/*.xml</include>
+          <include>**/*.properties</include>
         </includes>
       </resource>
       <resource>

Modified: struts/flow/trunk/xdocs/guess-example.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/xdocs/guess-example.xml?rev=371161&r1=371160&r2=371161&view=diff
==============================================================================
--- struts/flow/trunk/xdocs/guess-example.xml (original)
+++ struts/flow/trunk/xdocs/guess-example.xml Sat Jan 21 17:32:01 2006
@@ -15,77 +15,56 @@
       
       <section name="Flow Code">
       <a name="flow"/>
-        <p>Here is what the flow code looks like:
+        <p>The core of the number guessing game application is the NumberGuess controller.  This controller defines two actions, <code>play</code> and <code>endGame</code>.  Here is what the flow code looks like:
         </p>
 <pre>
-function main() {
-
-  var random =  Math.round( Math.random() * 9 ) + 1;
-  var hint = "No hint for you!"
-  var guesses = 0;
-
-  while (true) {
-
-    // send guess page to user and wait for response
-    forwardAndWait("failure", 
-       { "random"  : random, 
-         "hint"    : hint,
-         "guesses" : guesses} );
-
-    // process user's guess
-    var guess = parseInt( struts.param.guess );
-    guesses++;
-    if (guess) {
-      if (guess > random) {
-        hint = "Nope, lower!"
-      } 
-      else if (guess &lt; random) {
-        hint = "Nope, higher!"
-      } 
-      else {
-        // correct guess
-        break;
+NumberGuess = function() {
+  
+  this.play = function() {
+    this.random =  Math.round( Math.random() * 9 ) + 1;
+    this.hint = "No hint for you!"
+    this.guesses = 0;
+  
+    while (true) {
+      // send guess page to user and wait for response
+      flow.wait();
+    
+      // process user's guess
+      this.guess = parseInt( params.guess );
+      this.guesses++;
+      if (this.guess) {
+        if (this.guess > this.random) {
+          this.hint = "Nope, lower!"
+        } 
+        else if (this.guess &lt; this.random) {
+          this.hint = "Nope, higher!"
+        } 
+        else {
+          // correct guess
+          break;
+        }
       }
     }
+  
+    // send success page to user
+    flash.guesses = this.guesses;
+    flash.random = this.random;
+    flow.redirect( { "action" : "endGame" } );
   }
 
-  // send success page to user
-  forwardAndWait("success", 
-     {"random"  : random, 
-      "guess"   : guess, 
-      "guesses" : guesses} );
+  this.endGame = function() {}
 }
 </pre>
-        <p>Notice how the program loops until the number is guessed, even though pages are being sent to the 
-        browser to gather user input.</p>
+        <p>Notice in the <code>play()</code> function how the program loops until the number is guessed, even though pages are being sent to the 
+        browser to gather user input.  Once the number is guessed correctly, the number of guesses and correct number are stored in the "flash" object, which is a temporary storage location that allows you to pass data across redirects.  The framework handles storing the flash object in the session, then populating the controller variables from its contents on the very next user request.  Struts Flow also takes care of cleaning up the flash data from the session once it is used.</p>
+        
     </section>
-    <section name="Struts Configuration">
-    <a name="struts"/>
-        <p>To configure this application with Struts, the following action mapping and plug-in are defined in <code>struts-config.xml</code>:</p>
-<pre>
-&lt;action-mappings>
-
-    &lt;action    path="/guess"
-               type="net.sf.struts.flow.FlowAction"
-          className="net.sf.struts.flow.FlowMapping">
-           
-      &lt;set-property property="function"   value="main"/>     
-      &lt;forward name="failure"              path="/guess.jsp"/>
-      &lt;forward name="success"              path="/success.jsp"/>
-    &lt;/action>
-&lt;/action-mappings>   
-
-
-&lt;plug-in className="net.sf.struts.flow.FlowPlugIn">
-    &lt;set-property property="scripts" value="/WEB-INF/numberguess.js" />
-&lt;/plug-in>
-</pre>
-    <p> The <code>function</code> property of the custom action mapping tells <code>FlowAction</code> which
-    JavaScript function to call.</p>
-  </section>
   <section name="JSP Presentation">
   <a name="jsp"/>
-        <p>To gather the user's guess, <code>guess.jsp</code> generates a form:</p>
+  <p>
+        You might notice we aren't explicitly forwarding to any JSP pages.  Struts Flow will automatically forward the request to a JSP page with the same name as the action.  Therefore, when we "wait" in the <code>play()</code> action, the <code>jsp/play.jsp</code> page is shown.
+        </p>
+        <p>To gather the user's guess, <code>play.jsp</code> generates a form:</p>
 <pre>
 &lt;html>
 &lt;head>
@@ -99,7 +78,7 @@
   
   &lt;h3>You've guessed &lt;%= request.getAttribute("guesses") %> times.&lt;/h3>
   
-  &lt;form method="post" action="guess.do">
+  &lt;form method="post" action="play.do">
     &lt;input type="hidden" name="contid" value='&lt;%= request.getAttribute("contid") %>' />
     &lt;input type="text" name="guess"/>
     &lt;input type="submit"/>
@@ -109,7 +88,9 @@
 &lt;/html>
 </pre>
 <p>The hidden input variable <code>contid</code> stores the continuation to load from when the form gets submitted.</p>
-        
+        <p>
+        And that's it!  There are no Struts configuration files to write, no flow transition files to keep in sync.  To add new pages to the application, like a high score list, just add a new function to the controller and its JSP page.
+        </p>
       </section>
   </body>
 </document>

Modified: struts/flow/trunk/xdocs/index.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/xdocs/index.xml?rev=371161&r1=371160&r2=371161&view=diff
==============================================================================
--- struts/flow/trunk/xdocs/index.xml (original)
+++ struts/flow/trunk/xdocs/index.xml Sat Jan 21 17:32:01 2006
@@ -9,37 +9,44 @@
     <section name="Struts Flow">
     <a name="overview"/>
       <p>
-Struts Flow is a port of <a href="http://cocoon.apache.org">Cocoon's</a> <a
-href="http://cocoon.apache.org/2.1/userdocs/flow/index.html">Control Flow</a> to Struts to allow complex workflow, like
-multi-form wizards, to be easily implemented using continuations-capable JavaScript. It provides the ability to describe
-the order of Web pages that have to be sent to the client, at any given point in time in an application. The flow
-scripts fulfill the role of Struts Actions, however, they can be used along side traditional Java-based Struts Actions.
+Struts Flow is a server-side Javascript web framework that brings rapid development and consistency to your presentation tier.  With native Ajax support, web applications can be easily developed on the client and server side with language consistency.  The dynamic Javascript language requires minimal code and is used to form a zero configuration approach to Action-based controllers.
+</p>
 
-        </p>
-        <p>This is an example of a Struts Flow server-side script which logs the user on to an application:
-        <pre>
-function login() {
-  userManager = struts.applicationScope["userManager"];
-  error = "";
-  while (struts.sessionScope["curUser"] == null) {
-    forwardAndWait("loginForm", {"error" : error});
-    user = struts.param["user"];
-    passwd = struts.param["passwd"];
-    if (userManager.login(user, passwd)) {
-      struts.sessionScope["curUser"] = user;
-    } else {
-      error = "Invalid login, please try again";
-    }
+        <p>Here is a Javascript controller for a simple "Hello World" application that contains a single action - <code>say</code> - that sets the name for the message:</p>
+<pre>
+HelloWorld = function() {
+  this.say = function() {
+    this.name = "Struts Flow!";
   }
-}  
-        </pre>
-        The <code>forwardAndWait()</code> method sends an HTML page to the user and waits for a response. When the form
-        is submitted, Struts Flow restores the variable values and restarts the script where it left off. There are more
+}
+</pre>
+        <p>
+        And the corresponding JSP file:
+        </p>
+<pre>
+&lt;html&gt;
+  &lt;body&gt;
+    Hello world from ${name}!
+  &lt;/body&gt;
+&lt;/html&gt;
+</pre>
+        <p>
+        That's it - zero configuration required!  The <code>say</code> action would be called using the <code>http://localhost:8080/example/HelloWord/say.do</code> URL.  There are more
         detailed examples in the <a href="#examples">Examples</a> section.
         </p>
+        
+        <p>Built on a port of <a
+href="http://cocoon.apache.org">Cocoon's</a> <a
+href="http://cocoon.apache.org/2.1/userdocs/flow/index.html">Control Flow</a>, Struts Flow enables complex workflow, like multi-form wizards, to be easily
+implemented using continuations-capable JavaScript. It provides the ability to
+describe the order of Web pages that have to be sent to the client, at any given
+point in time in an application. The flow scripts fulfill the role of Struts
+Actions, however, they can be used along side traditional Java-based Struts
+Actions.
+
+        </p>
         <p>
-        Since continuations are best implemented in Javascript, Struts Flow also focuses on making Javascript
-        easier to use and better integrated into the Java environment borrowing several ideas from <a 
+        To make the Javascript easier to use and better integrated into the Java environment borrowing several ideas from <a 
         href="http://groovy.codehaus.org">Groovy</a>.  First, information in Collections classes
         can be accessed using Javascript array (<code>foo[1]</code>) and object (<code>foo["bar"]</code>) notations.
         Also, Struts Flow uses <a href="http://www.json.org">JSON</a> to allow client-side Javascript running
@@ -49,11 +56,8 @@
         added to them.  For example, to process each line of a text file, you can use the following closure:
         </p>
 <pre>
-  file = new java.io.File("foo.txt");
-  file.eachLine(
-    function(line) {
-      print(line);
-    }
+  new File("foo.txt").eachLine(
+    function(line) { print(line); }
   );
 </pre>
         <p>
@@ -65,6 +69,8 @@
       <section name="Features">
       <a name="features"/>
             <ul>
+              <li><a href="http://www.rubyonrails.org">Ruby on Rails</a>-style zero configuration controllers</li>
+              <li>"Flash" object support for passing data between requests</li>
               <li>Easily script complex workflows</li>
               <li>Full access to Struts features</li>
               <li>Can exist side-by-side regular Struts actions</li>
@@ -86,7 +92,7 @@
           to keep your Struts Flow scripts short and to the point. A list of the extensions is also on the left under
           the heading"Java Enhancements".
         </p>
-             <p>The following examples show how Struts Flow can be used:
+             <p>Each of the following examples show how Struts Flow can be used with zero configuration:
              </p>
             <ul>
                 <li><a href="guess-example.html">Number Guess Game Example</a> - A simple number guessing game</li>
@@ -103,6 +109,8 @@
       <a name="new"/>
         <subsection name="0.5 - Unreleased">
             <ul>
+              <li>Zero configuration controllers</li>
+              <li>Experimental portlet support</li>
               <li>Added better Collections support within Javascript</li>
               <li>Upgraded Rhino library to 1.6 which features native continuations support</li>
               <li>Added framework for adding methods and properties to core Java API classes</li>
@@ -145,7 +153,7 @@
       <section name="Requirements">
       <a name="requirements"/>
           <p>
-            Struts-specific features of Struts Flow requires Struts 1.1 or greater.
+            Struts-specific features of Struts Flow requires Struts 1.3 or greater.
           </p>
       </section>
  </body>

Modified: struts/flow/trunk/xdocs/remote-example.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/xdocs/remote-example.xml?rev=371161&r1=371160&r2=371161&view=diff
==============================================================================
--- struts/flow/trunk/xdocs/remote-example.xml (original)
+++ struts/flow/trunk/xdocs/remote-example.xml Sat Jan 21 17:32:01 2006
@@ -24,100 +24,93 @@
         <p>Here is what the flow code looks like:
         </p>
 <pre>
-var random;
-var guesses;
-
-function main() {
-
-  random =  Math.round( Math.random() * 9 ) + 1;
-  var hint = "No hint for you!"
-  guesses = 0;
-
-  while (true) {
-
-    // send guess page to user and wait for response.  Specify only cheat() 
-    // can be called remotely.
-    forwardAndWait("failure", 
-       { "hint"    : hint,
-         "guesses" : guesses},
-       ["cheat"]);
-
-    print("processing a user guess "+struts.param.guess);
-    // process user's guess
-    var guess = parseInt( struts.param.guess );
-    guesses++;
-    if (guess) {
-      if (guess > random) {
-        hint = "Nope, lower!"
-      } 
-      else if (guess &lt; random) {
-        hint = "Nope, higher!"
-      } 
-      else {
-        // correct guess
-        break;
+NumberGuess = function() {
+  
+  this.play = function() {
+  
+    this.random =  Math.round( Math.random() * 9 ) + 1;
+    this.hint = "No hint for you!"
+    this.guesses = 0;
+  
+    while (true) {
+  
+      // send guess page to user and wait for response
+      flow.wait();
+  
+      // process user's guess
+      this.guess = parseInt( params.guess );
+      this.guesses++;
+      if (this.guess) {
+        if (this.guess &gt; this.random) {
+          this.hint = "Nope, lower!"
+        } 
+        else if (this.guess &lt; this.random) {
+          this.hint = "Nope, higher!"
+        } 
+        else {
+          // correct guess
+          break;
+        }
       }
     }
+  
+    // send success page to user
+    flash.guesses = this.guesses;
+    flash.random = this.random;
+    flow.redirect( { "action" : "endGame" } );
   }
 
-  // send success page to user
-  forwardAndWait("success", 
-     {"random"  : random, 
-      "guess"   : guess, 
-      "guesses" : guesses} );
-}
+  this.endGame = function() {}
 
-function cheat() {
-    guesses += 5;
-    return {"secret":random, "guesses":guesses};
+  this.cheat = function() {
+      this.guesses += 5;
+      return {"secret":this.random, "guesses":this.guesses};
+  }    
 }
 </pre>
-        <p>The big change here is several variables have been moved to outside the function to allow access by
-        the new cheat() function.  The cheat() function adds 5 to the number of guesses then returns the secret
-        number.  Struts Flow converts the returned object into <a href="http://www.json.org">JSON</a> and returns
+        <p>The only change to the original is a new <code>cheat()</code> function that provides the secret word at the expense of 5 extra guesses.  Struts Flow converts the returned object into <a href="http://www.json.org">JSON</a> and returns
         it to the client.</p>
     </section>
  <section name="JSP Presentation">
  <a name="jsp"/>
         <p>This example adds the "cheat" button to the number guessing form, <code>guess.jsp</code>.  When
-        pressed, the Javascript uses the clientFlow.js library to call the cheat() function on the server.</p>
+        pressed, the Javascript uses <a href="http://dojotoolkit.org">Dojo Javascript Toolkit</a> to call the cheat() function on the server.</p>
 <pre>
-&lt;?xml version="1.0"?>
-&lt;html>
-&lt;head>
-  &lt;title>Struts Flow number guessing game&lt;/title>
-    &lt;script type="text/javascript">
+&lt;html&gt;
+&lt;head&gt;
+  &lt;title&gt;Struts Flow number guessing game - Remote edition&lt;/title&gt;
+    &lt;script type="text/javascript"&gt;
   &lt;!--
-function init() {
-    this.contid = "&lt;%=request.getAttribute("contid")%>";
-    this.client = new ClientFlow("guess.do");
-}   
 function cheat() {
-    result = client.call("cheat", contid);
-    alert("The secret number is "+result.secret+". After applying a penalty, you have guessed "+result.guesses+" times");
-    contid = result.contid;
+    dojo.io.bind({
+        url:  'play.do?FlowCall=cheat&amp;contid=&lt;%= request.getAttribute("contid") %&gt;',
+        type: "text/javascript",
+        load: function(type, data, evt) {
+            eval("data = "+data);
+            alert("The secret number is "+data.secret+". After applying a penalty, you have guessed "+data.guesses+" times");
+        }
+    });
 }
-    -->
-  &lt;/script>
-  &lt;script type="text/javascript" src="clientFlow.js" />
-&lt;/head>
-&lt;body onload="init()">
+    --&gt;
+  &lt;/script&gt;
+  &lt;script type="text/javascript" src="../dojo-io.js"&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
 
-  &lt;h1>Guess the Number Between 1 and 10&lt;/h1>
-  
-  &lt;h2>&lt;%= request.getAttribute("hint") %>&lt;/h2>
+  &lt;h1&gt;Guess the Number Between 1 and 10&lt;/h1&gt;
   
-  &lt;h3>You've guessed &lt;%= request.getAttribute("guesses") %> times.&lt;/h3>
+  &lt;h2&gt;&lt;%= request.getAttribute("hint") %&gt;&lt;/h2&gt;
   
-  &lt;form method="post" action="guess.do">
-    &lt;input type="hidden" name="contid" value='&lt;%= request.getAttribute("contid") %>' />
-    &lt;input type="text" name="guess"/>
-    &lt;input type="submit"/>
-    &lt;input type="button" onclick="cheat()" value="Cheat" />
-  &lt;/form>
+  &lt;h3&gt;You've guessed &lt;%= request.getAttribute("guesses") %&gt; times.&lt;/h3&gt;
   
-&lt;/body>
-&lt;/html>
+  &lt;form method="post" action="play.do"&gt;
+    &lt;input type="hidden" name="contid" value='&lt;%= request.getAttribute("contid") %&gt;' /&gt;
+    &lt;input type="text" name="guess"/&gt;
+    &lt;input type="submit"/&gt;
+    &lt;input type="button" onclick="cheat()" value="Cheat" /&gt;
+  &lt;/form&gt;
+&lt;/body&gt;
+&lt;/html&gt;
 </pre>
 <p>The key to the function call executing in the server flow is passing the continuation id to the client flow
 instance.

Modified: struts/flow/trunk/xdocs/templates-example.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/xdocs/templates-example.xml?rev=371161&r1=371160&r2=371161&view=diff
==============================================================================
--- struts/flow/trunk/xdocs/templates-example.xml (original)
+++ struts/flow/trunk/xdocs/templates-example.xml Sat Jan 21 17:32:01 2006
@@ -40,100 +40,97 @@
 flow.load("/templates/template.js");
 
 ...
+    // Change our endGame action to render a template
+    this.endGame = function() {
+        renderTemplate("endGame", this);
+    }
+...
+
+// 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();
+}
 
-// 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 = struts.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;
-   }
+function renderTemplate(page, bizdata) {
+    var res = flow.context.response;
+    var stream = struts.servletContext.getResourceAsStream("/WEB-INF/templates/jt/"+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);
+    }
 }
 
-// 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;
+// Replace the usual implementation with ours that renders the template before forwarding
+FOM_Flow.prototype._wait=renderTemplateAndWait;
 </pre>
-        <p>The <code>_forwardAndWait()</code> function is an internal function that Struts Flow calls to do the actual
-        forward and continuation creation. We are replacing it as the <code>forwardAndWait()</code> function has useful
+        <p>The <code>_wait()</code> function is an internal function that Struts Flow calls to do the actual
+        forward and continuation creation. We are replacing it as the <code>wait()</code> function has useful
         logic for handling remote function calls that we don't want to duplicate. This process will most likely change
         as Javascript Templates are better integrated into Struts Flow. Our new <code>renderTemplate()</code> function
         ensures it is a real page request then generates the HTML by processing the passed template page and data.</p>
     </section>
  <section name="Javascript Templates Presentation (Server Side)">
  <a name="jt"/>
-        <p>The <code>guess.jsp</code> has been replaced by <code>guess.jt</code> which has basically the same content,
+        <p>The <code>play.jsp</code> has been replaced by <code>play.jt</code> which has basically the same content,
         but follows the Javascript Templates format rather than JSP. The client-side <code>cheat()</code> function
         retrieves the <code>cheat.jt</code> template on the server, then uses it to process the results from the
         server-side <code>cheat()</code> remote function call. The results of the template processing replace the hint
         message.</p>
+        <p>This is what our new <code>play.jt</code> template looks like:</p>
 <pre>
-&lt;html>
-&lt;head>
-  &lt;title>Struts Flow number guessing game&lt;/title>
-    &lt;script type="text/javascript">
+&lt;html&gt;
+&lt;head&gt;
+  &lt;title&gt;Struts Flow number guessing game&lt;/title&gt;
+    &lt;script type="text/javascript"&gt;
   &lt;!--
-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:  'play.do?FlowCall=cheat&amp;contid=${contid}',
+        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);
+                }
+            });
+        }
+    });
 }
-    -->
-  &lt;/script>
-  &lt;script type="text/javascript" src="clientFlow.js" />
-  &lt;script type="text/javascript" src="template.js" />
-&lt;/head>
-&lt;body onload="init()">
+    --&gt;
+  &lt;/script&gt;
+  &lt;script type="text/javascript" src="../../remote/dojo-io.js"&gt;&lt;/script&gt;
+  &lt;script type="text/javascript" src="../template.js"&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
 
-  &lt;h1>Guess the Number Between 1 and 10&lt;/h1>
-  
-  &lt;h2 id="hint">${hint}&lt;/h2>
+  &lt;h1&gt;Guess the Number Between 1 and 10&lt;/h1&gt;
   
-  &lt;h3>You've guessed ${guesses} times.&lt;/h3>
+  &lt;h2 id="hint"&gt;${hint}&lt;/h2&gt;
   
-  &lt;form method="post" action="guess.do">
-    &lt;input type="hidden" name="contid" value="${contid}" />
-    &lt;input type="text" name="guess"/>
-    &lt;input type="submit"/>
-    &lt;input type="button" onclick="cheat()" value="Cheat" />
-  &lt;/form>
+  &lt;h3&gt;You've guessed ${guesses} times.&lt;/h3&gt;
   
-  &lt;a href="../index.html">Return to index&lt;/a>  
+  &lt;form method="post" action="play.do"&gt;
+    &lt;input type="hidden" name="contid" value="${contid}" /&gt;
+    &lt;input type="text" name="guess"/&gt;
+    &lt;input type="submit"/&gt;
+    &lt;input type="button" onclick="cheat()" value="Cheat" /&gt;
+  &lt;/form&gt;
   
-&lt;/body>
-&lt;/html>
+&lt;/body&gt;
+&lt;/html&gt;
 </pre>
 <p>What is not obvious is Javascript Templates adds a <code>process()</code> function to the String object which allows us to process the response text of the <code>cheat.jt</code> call directly.  The <code>cheat.jt</code> file looks like this:
 </p>

Modified: struts/flow/trunk/xdocs/wizard-example.xml
URL: http://svn.apache.org/viewcvs/struts/flow/trunk/xdocs/wizard-example.xml?rev=371161&r1=371160&r2=371161&view=diff
==============================================================================
--- struts/flow/trunk/xdocs/wizard-example.xml (original)
+++ struts/flow/trunk/xdocs/wizard-example.xml Sat Jan 21 17:32:01 2006
@@ -18,44 +18,41 @@
         To demonstrate the wizard, this example shows a user registration process with three screens: names, hobbies, and a summary 
         display.  A <code>java.util.Map</code> is used to store the information submitted by the forms.  
         To keep it simple, no Struts JSP tags are used, but could be by wrapping model with an <code>ActionForm</code>.
-        There are three parts to the example: the flow code which uses the Wizard object, the Struts config, and the JSP's that display the output.  
+        There are two parts to the example: the flow code which uses the Wizard object, and the JSP's that display the output - again, no Struts configuration file necessary.  
         </p>
       </section>
       <section name="Flow Code">
       <a name="flow"/>
-        <p>Here is what the flow code looks like:
+        <p>Here is what the flow code for the Registration controller looks like:
         </p>
 <pre>
+flow.load("/WEB-INF/wizard/flow/wizard.js");
 
-importPackage(Packages.java.util);
-flow.load("/WEB-INF/wizard.js");
+Registration = function() {
 
-function main() {
-  var model = new HashMap();
+    this.start = function() {
+        var model = new java.util.HashMap();
 
-  var wizard = new Wizard(model);
-
-  // plug in custom population method
-  wizard.populate = populate;
-
-  // plug in custom validation method
-  wizard.validate = validate;
+        var wizard = new Wizard(model);
+        wizard.populate = populate;
+        wizard.validate = validate;
       
-  wizard.showForm("name-form", {
+        wizard.showForm( { "action" : "name-form" }, {
                   "title" : "User Name Information"
                   });
-  wizard.showForm("hobbies-form", {
+        wizard.showForm( { "action" : "hobbies-form" }, {
                   "title" : "User Hobbies"
                   });
-  wizard.showForm("summary-form", {
+        wizard.showForm( { "action" : "summary-form" } , {
                   "title" : "User Summary"
                   });  
+    };              
 }
 
 function populate() {
-  m = struts.paramValues;
-  for (i = m.keySet().iterator(); i.hasNext(); ) {
-    key = i.next();
+  var m = struts.paramValues;
+  for (var i = m.keySet().iterator(); i.hasNext(); ) {
+    var key = i.next();
     this.model.put(key, m.get(key)[0]);
   }
   // Bug in commons-chain prevents this
@@ -67,41 +64,12 @@
     return "Name must be specified";
   }
 }
-
 </pre>
         <p>Notice the logic for the wizard itself is really simple.  The validation and population methods can either be manually done as 
         show here, or use frameworks like commons-validator and commons-beanutils.  Notice also there is no handing of navigation as that 
         is all taken care of by the Wizard object.
         </p>
     </section>
-    <section name="Struts Configuration">
-    <a name="struts"/>
-        <p>To configure this application with Struts, the following action mapping and plug-in are defined in <code>struts-config.xml</code>:</p>
-<pre>
-  &lt;action-mappings>
-
-    &lt;action    path="/registration"
-               type="net.sf.struts.flow.FlowAction"
-          className="net.sf.struts.flow.FlowMapping">
-          
-      &lt;set-property property="function" value="main" />
-
-      &lt;forward name="name-form"              path="/name-form.jsp"/>
-      &lt;forward name="hobbies-form"              path="/hobbies-form.jsp"/>
-      &lt;forward name="summary-form"              path="/summary-form.jsp"/>
-    &lt;/action>
- &lt;/action-mappings>   
-
-
-&lt;action-mappings>
-
-&lt;plug-in className="net.sf.struts.flow.FlowPlugIn">
-    &lt;set-property property="scripts" value="/WEB-INF/wizard-flow.js" />
-&lt;/plug-in>
-</pre>
-    <p> The <code>function</code> property of the custom action mapping tells <code>FlowAction</code> which
-    JavaScript function to call.  Each form in the wizard has its own forward.</p>
-  </section>
   <section name="JSP Presentation">
   <a name="jsp"/>
         <p>This is the first form in the wizard:</p>
@@ -118,7 +86,7 @@
   &lt;/p>
 
   &lt;center style="color:red">&lt;%=(request.getAttribute("errors") != null ? request.getAttribute("errors") : "")%>&lt;/center>
-  &lt;form action="registration.do" method="POST">
+  &lt;form action="start.do" method="POST">
 
   &lt;% java.util.Map form = (java.util.Map)request.getAttribute("form"); %>
   &lt;table>



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