Author: dolander
Date: Wed Aug 11 21:40:11 2004
New Revision: 36269

Added:
   incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/
   
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/Controller.jpf
   
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/index.jsp
   
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/CtFormJspost.xml
Modified:
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
   incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/index.jsp
   
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
Log:
Add a boolean property to the Form which will create the Form Post JavaScript.
This is useful if you want to have anchors outside of forms which post the form.



Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    Wed Aug 11 21:40:11 2004
@@ -207,7 +207,6 @@
     private InputHiddenTag.State _hiddenState = new InputHiddenTag.State();
 
     private String _focus = null;                  // The name of the field to 
receive focus, if any.
-    private boolean _reportedError = false;
     // @todo: did we support location in 8.1?  How?
     private String _location = null;               // The location hash to 
append to the url.
     private String _scope = null;                  // The scope (request or 
session) under which our associated bean is stored
@@ -225,6 +224,7 @@
     private ArrayList _idList = null;
     private ModuleConfig _appConfig = null;        // The application 
configuration for our module.
     private boolean _setRealName = false;
+    private boolean _formSubmit = false;
     private Map _params;
 
     /**
@@ -522,6 +522,19 @@
     }
 
     /**
+     * Generate the JavaScript which will submit a form.  This is usually 
generated if the
+     * form contains anchors that are used to submit the form.  This will make 
sure the JavaScript is
+     * always generated.
+     * @param formSubmit boolean value indicating that the form submit 
JavaScript should be generated.  Default is false.
+     * @netui:attribute required="false" rtexprvalue="true"
+     * description="Generate the form submit JavaScript even if the form does 
not contain anchors."
+     * @netui.tldx:attribute category="misc"
+     */
+    public void setGenJavaScriptFormSubmit(boolean formSubmit) {
+        _formSubmit = formSubmit;
+    }
+
+    /**
      * Adds a URL parameter to the generated hyperlink.
      * @param name  - the name of the parameter to be added.
      * @param value - the value of the parameter to be added (a String or 
String[]).
@@ -843,6 +856,13 @@
             }
         }
 
+        if (_formSubmit) {
+            JavaScriptUtils jsu = getJavaScriptUtils(request);
+            String s = jsu.writeAnchorFormSubmit(getScriptReporter());
+            if (s != null)
+                results.append(s);
+        }
+
         // output any generated javascript
         if (idScript != null)
             results.append(idScript);
@@ -900,9 +920,9 @@
         _focusMap = null;
         if (_idList != null)
             _idList.clear();
-        _reportedError = false;
         _appConfig = null;
         _setRealName = false;
+        _formSubmit = false;
         _params = null;
     }
 

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/Controller.jpf
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/Controller.jpf
  Wed Aug 11 21:40:11 2004
@@ -0,0 +1,47 @@
+package coretags.form.jspost;
+
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+
+/**
+ * This is the default controller for a blank web application.
+ */
[EMAIL PROTECTED]
+public class Controller extends PageFlowController
+{
+    @Jpf.Action(
+        forwards={
+           @Jpf.Forward(name="index", path="index.jsp")
+        }
+    )
+    protected Forward begin()
+    {
+        return new Forward("index");
+    }
+
+
+
+        
+    @Jpf.Action(forwards = { 
+    @Jpf.Forward(name = "success", path = "index.jsp")
+})
+        protected Forward post()        {
+        Forward forward = new Forward("success");
+        
+                return forward;
+    }
+                }
+
[EMAIL PROTECTED](value = { 
+    "<!-- This data is auto-generated. Hand-editing this section is not 
recommended. -->", 
+    "<view-properties>", 
+    "<pageflow-object id='action:begin.do'><property value='80' 
name='x'/><property value='100' name='y'/></pageflow-object>", 
+    "<pageflow-object id='page:index.jsp'><property value='220' 
name='x'/><property value='100' name='y'/></pageflow-object>", 
+    "<pageflow-object id='forward:[EMAIL PROTECTED]:begin.do@'><property 
value='116,140,140,164' name='elbowsX'/><property value='92,92,92,92' 
name='elbowsY'/><property value='East_1' name='fromPort'/><property 
value='West_1' name='toPort'/><property value='index' 
name='label'/></pageflow-object>", 
+    "<pageflow-object id='action:post.do'><property value='340' 
name='x'/><property value='100' name='y'/></pageflow-object>", 
+    "<pageflow-object id='forward:[EMAIL PROTECTED]:post.do@'><property 
value='304,280,280,256' name='elbowsX'/><property value='92,92,92,92' 
name='elbowsY'/><property value='West_1' name='fromPort'/><property 
value='East_1' name='toPort'/><property value='success' 
name='label'/></pageflow-object>", 
+    "<pageflow-object id='action-call:@page:[EMAIL 
PROTECTED]@action:post.do@'><property value='256,280,280,304' 
name='elbowsX'/><property value='92,92,92,92' name='elbowsY'/><property 
value='East_1' name='fromPort'/><property value='West_1' 
name='toPort'/></pageflow-object>", 
+    "</view-properties>"
+})
+interface VIEW_PROPERTIES { }

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/index.jsp
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/form/jspost/index.jsp
       Wed Aug 11 21:40:11 2004
@@ -0,0 +1,26 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" 
uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" 
uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+<netui:html>
+    <head>
+        <netui:base/>
+    </head>
+    <body>
+        <h4>Post Form With an Anchor</h4>
+        <p style="color:green">This test will submit a form using an anchor 
+        that is outside the form.  The form is told to output javascript which
+        is then used by the anchor.
+        <br>
+        To run this test hit the anchor.  The value of a hidden field should 
then appear.
+        <netui:form action="post" genJavaScriptFormSubmit="true">    
+            <input type="hidden" name="foo" value="value">  
+        </netui:form>
+
+        <netui:anchor action="begin" 
onClick='anchor_submit_form("Netui_Form_0","post.do");return false;'>Submit the 
form</netui:anchor>
+        <hr>
+        <p>Value: ${param.foo}</p>
+    </body>
+</netui:html>
+
+  
\ No newline at end of file

Modified: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/index.jsp
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/index.jsp   
(original)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/coretags/index.jsp   
Wed Aug 11 21:40:11 2004
@@ -22,6 +22,7 @@
     <li><a href="form/bean/Controller.jpf">Form Bean</a> &#8212; Test of the 
Form name, type and scope attributes</li>
     <li><a href="form/beanerror/Controller.jpf">Form Bean Error</a> &#8212; 
Test of Errors in the Form name, type and scope attributes</li>
     <li><a href="form/errors/Controller.jpf">Form Errors</a> &#8212; Form 
Errors</li>
+    <li><a href="form/jspost/Controller.jpf">Form JavaScript Post</a> &#8212; 
Post a form with JavaScript outside of the form.</li>
     <li><a href="form/nullbinding/Controller.jpf">Form Null Binding</a> 
&#8212; Form null binding tests</li>
     <li><a href="formatdate/errors/Controller.jpf">FormatDate Errors</a> 
&#8212; FormatDate tag errors and Formatter error reporting</li>
     <li><a href="formatdate/errorsinline/Controller.jpf">FormatDate Inline 
Errors</a> &#8212; Formatter error reporting with inline errors</li>

Modified: 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
   (original)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
   Wed Aug 11 21:40:11 2004
@@ -1850,6 +1850,19 @@
          </features>
       </test>
       <test>
+         <name>CtFormJspost</name>
+         <description>Post a Form with JavaScript</description>
+         <webapp>coreWeb</webapp>
+         <categories>
+            <category>bvt</category>
+            <category>tags</category>
+         </categories>
+         <features>
+            <feature>Form</feature>
+            <feature>JavaScript</feature>
+         </features>
+      </test>
+      <test>
          <name>CtFormNullBinding</name>
          <description>Binding to null in the Form attributes</description>
          <webapp>coreWeb</webapp>

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/CtFormJspost.xml
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/CtFormJspost.xml
  Wed Aug 11 21:40:11 2004
@@ -0,0 +1,230 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ses:recorderSession 
xmlns:ses="http://beehive.apache.org/netui/tools/testrecorder/2004/session";>
+   <ses:sessionName>CtFormJspost</ses:sessionName>
+   <ses:tester>Daryl</ses:tester>
+   <ses:startDate>11 Aug 2004, 10:03:17.290 PM MDT</ses:startDate>
+   <ses:description>Post a form with JavaScript.</ses:description>
+   <ses:tests>
+      <ses:test>
+         <ses:testNumber>1</ses:testNumber>
+         <ses:request>
+            <ses:protocol>HTTP</ses:protocol>
+            <ses:protocolVersion>1.1</ses:protocolVersion>
+            <ses:host>localhost</ses:host>
+            <ses:port>8080</ses:port>
+            <ses:uri>/coreWeb/coretags/form/jspost/Controller.jpf</ses:uri>
+            <ses:method>GET</ses:method>
+            <ses:parameters/>
+            <ses:cookies>
+               <ses:cookie>
+                  <ses:name>JSESSIONID</ses:name>
+                  <ses:value>2BEC3F31AC39411FF012CCAAE55C0EBC</ses:value>
+               </ses:cookie>
+            </ses:cookies>
+            <ses:headers>
+               <ses:header>
+                  <ses:name>accept</ses:name>
+                  <ses:value>image/gif, image/x-xbitmap, image/jpeg, 
image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, 
application/msword, application/x-shockwave-flash, */*</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>accept-encoding</ses:name>
+                  <ses:value>gzip, deflate</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>accept-language</ses:name>
+                  <ses:value>en-us</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>connection</ses:name>
+                  <ses:value>Keep-Alive</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>cookie</ses:name>
+                  
<ses:value>JSESSIONID=2BEC3F31AC39411FF012CCAAE55C0EBC</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>host</ses:name>
+                  <ses:value>localhost:8080</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>user-agent</ses:name>
+                  <ses:value>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 
5.1; .NET CLR 2.0.40607)</ses:value>
+               </ses:header>
+            </ses:headers>
+         </ses:request>
+         <ses:response>
+            <ses:statusCode>200</ses:statusCode>
+            <ses:reason/>
+            <ses:responseBody>&lt;!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01 
Transitional//EN"
+       "http://www.w3.org/TR/html4/loose.dtd";>
+&lt;html lang="en">
+&lt;head>
+        &lt;base 
href="http://localhost:8080/coreWeb/coretags/form/jspost/index.jsp";>
+    &lt;/head>
+    &lt;body>
+        &lt;h4>Post Form With an Anchor&lt;/h4>
+        &lt;p style="color:green">This test will submit a form using an anchor 
+        that is outside the form.  The form is told to output javascript which
+        is then used by the anchor.
+        &lt;br>
+        To run this test hit the anchor.  The value of a hidden field should 
then appear.
+        &lt;form id="Netui_Form_0" 
action="/coreWeb/coretags/form/jspost/post.do" method="post">    
+            &lt;input type="hidden" name="foo" value="value">  
+        &lt;/form>
+
+        &lt;a href="/coreWeb/coretags/form/jspost/begin.do" 
onclick='anchor_submit_form("Netui_Form_0","post.do");return false;'>Submit the 
form&lt;/a>
+        &lt;hr>
+        &lt;p>Value: &lt;/p>
+    &lt;/body>
+
+&lt;script language="JavaScript" type="text/JavaScript">
+&lt;!--
+
+// **** This section contains functions typically run as events ****
+
+
+// submit the form from an Anchor or ImageAnchor
+// Search for the form by actionName,
+// Replace the action with the passed in action
+// Submit the form
+function anchor_submit_form(netuiName, newAction)
+{
+  for (var i=0; i&lt;document.forms.length; i++) {
+     if (document.forms[i].id == netuiName) {
+        document.forms[i].method = "POST";
+        document.forms[i].action = newAction;
+        document.forms[i].submit();
+     }
+   }
+}
+-->
+&lt;/script>
+
+
+&lt;/html></ses:responseBody>
+         </ses:response>
+      </ses:test>
+      <ses:test>
+         <ses:testNumber>2</ses:testNumber>
+         <ses:request>
+            <ses:protocol>HTTP</ses:protocol>
+            <ses:protocolVersion>1.1</ses:protocolVersion>
+            <ses:host>localhost</ses:host>
+            <ses:port>8080</ses:port>
+            <ses:uri>/coreWeb/coretags/form/jspost/post.do</ses:uri>
+            <ses:method>POST</ses:method>
+            <ses:parameters>
+               <ses:parameter>
+                  <ses:name>foo</ses:name>
+                  <ses:value>value</ses:value>
+               </ses:parameter>
+            </ses:parameters>
+            <ses:cookies>
+               <ses:cookie>
+                  <ses:name>JSESSIONID</ses:name>
+                  <ses:value>2BEC3F31AC39411FF012CCAAE55C0EBC</ses:value>
+               </ses:cookie>
+            </ses:cookies>
+            <ses:headers>
+               <ses:header>
+                  <ses:name>accept</ses:name>
+                  <ses:value>image/gif, image/x-xbitmap, image/jpeg, 
image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, 
application/msword, application/x-shockwave-flash, */*</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>accept-encoding</ses:name>
+                  <ses:value>gzip, deflate</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>accept-language</ses:name>
+                  <ses:value>en-us</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>cache-control</ses:name>
+                  <ses:value>no-cache</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>connection</ses:name>
+                  <ses:value>Keep-Alive</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>content-length</ses:name>
+                  <ses:value>9</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>content-type</ses:name>
+                  <ses:value>application/x-www-form-urlencoded</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>cookie</ses:name>
+                  
<ses:value>JSESSIONID=2BEC3F31AC39411FF012CCAAE55C0EBC</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>host</ses:name>
+                  <ses:value>localhost:8080</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>referer</ses:name>
+                  
<ses:value>http://localhost:8080/coreWeb/coretags/form/jspost/Controller.jpf</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>user-agent</ses:name>
+                  <ses:value>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 
5.1; .NET CLR 2.0.40607)</ses:value>
+               </ses:header>
+            </ses:headers>
+         </ses:request>
+         <ses:response>
+            <ses:statusCode>200</ses:statusCode>
+            <ses:reason/>
+            <ses:responseBody>&lt;!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01 
Transitional//EN"
+       "http://www.w3.org/TR/html4/loose.dtd";>
+&lt;html lang="en">
+&lt;head>
+        &lt;base 
href="http://localhost:8080/coreWeb/coretags/form/jspost/index.jsp";>
+    &lt;/head>
+    &lt;body>
+        &lt;h4>Post Form With an Anchor&lt;/h4>
+        &lt;p style="color:green">This test will submit a form using an anchor 
+        that is outside the form.  The form is told to output javascript which
+        is then used by the anchor.
+        &lt;br>
+        To run this test hit the anchor.  The value of a hidden field should 
then appear.
+        &lt;form id="Netui_Form_0" 
action="/coreWeb/coretags/form/jspost/post.do" method="post">    
+            &lt;input type="hidden" name="foo" value="value">  
+        &lt;/form>
+
+        &lt;a href="/coreWeb/coretags/form/jspost/begin.do" 
onclick='anchor_submit_form("Netui_Form_0","post.do");return false;'>Submit the 
form&lt;/a>
+        &lt;hr>
+        &lt;p>Value: value&lt;/p>
+    &lt;/body>
+
+&lt;script language="JavaScript" type="text/JavaScript">
+&lt;!--
+
+// **** This section contains functions typically run as events ****
+
+
+// submit the form from an Anchor or ImageAnchor
+// Search for the form by actionName,
+// Replace the action with the passed in action
+// Submit the form
+function anchor_submit_form(netuiName, newAction)
+{
+  for (var i=0; i&lt;document.forms.length; i++) {
+     if (document.forms[i].id == netuiName) {
+        document.forms[i].method = "POST";
+        document.forms[i].action = newAction;
+        document.forms[i].submit();
+     }
+   }
+}
+-->
+&lt;/script>
+
+
+&lt;/html></ses:responseBody>
+         </ses:response>
+      </ses:test>
+   </ses:tests>
+   <ses:endDate>11 Aug 2004, 10:03:24.380 PM MDT</ses:endDate>
+   <ses:testCount>2</ses:testCount>
+</ses:recorderSession>

Reply via email to