beehive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dolan...@apache.org
Subject svn commit: r124237 - in incubator/beehive/trunk/netui: src/tags-html/org/apache/beehive/netui/tags/html test/webapps/drt/coreWeb/idmap/genScopeId test/webapps/drt/testRecorder/config test/webapps/drt/testRecorder/tests
Date Wed, 05 Jan 2005 18:19:21 GMT
Author: dolander
Date: Wed Jan  5 10:19:19 2005
New Revision: 124237

URL: http://svn.apache.org/viewcvs?view=rev&rev=124237
Log:
Add an generateScopeId boolean attribute to the ScriptContainer (and Html) tag.  This will
generate
a unique new scope id so that all ids should be unique.

Added a test of the feature.



Added:
   incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/
   incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/Controller.jpf
   incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/index.jsp
   incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/IdMapGenScopeId.xml
Modified:
   incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
   incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java
   incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml

Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java?view=diff&rev=124237&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java&r1=124236&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java&r2=124237
==============================================================================
--- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
(original)
+++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Html.java
Wed Jan  5 10:19:19 2005
@@ -116,7 +116,7 @@
     private boolean _useLocale = false;     // include xml:lang=defaultLocale.getLanguage()
     private ArrayList _errors;              // errors
     private IErrorReporter _containerErrors; //Check to see if there is a parent error reporter
-    private int _uniqueId = 0;              // unique id sequence
+    //private int _uniqueId = 0;              // unique id sequence
 
     private String _docType;                // The document type
 
@@ -316,10 +316,10 @@
      * of this tag.
      * @return a unique integer
      */
-    public int getNextId()
-    {
-        return _uniqueId++;
-    }
+    //public int getNextId()
+    //{
+    //    return _uniqueId++;
+    //}
 
     /**
      * Return an ArrayList of the errors
@@ -390,7 +390,7 @@
         _useLocale = false;
         _errors = null;
         _containerErrors = null;
-        _uniqueId = 0;
+        //_uniqueId = 0;
         pageContext.getRequest().removeAttribute(HTML_TAG_ID);
     }
 }

Modified: incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java?view=diff&rev=124237&p1=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java&r1=124236&p2=incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java&r2=124237
==============================================================================
--- incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java
(original)
+++ incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/ScriptContainer.java
Wed Jan  5 10:19:19 2005
@@ -73,6 +73,7 @@
     private HashMap _idToIdMap;
     private HashMap _idToNameMap;
     private HashMap _anchorRewriters;
+    private boolean _getScope = false;
     private boolean _runAtClient = false;
     private boolean _writeScript = false;
     private boolean _writeInitScript = false;
@@ -258,6 +259,19 @@
     }
 
     /**
+     * If true generate a scope id for this script container.  If this is set to true
+     * and a scopeId is also set, the scopeId set will be written.
+     * @jsptagref.attributedescription Automatically generate a scopeId for this script container.
+     * @jsptagref.databindable true
+     * @jsptagref.attributesyntaxvalue <i>string_generateScopeId</i>
+     * @netui:attribute required="false" rtexprvalue="true"
+     * description="Automatically generate a ScopeId."
+     */
+    public void setGenerateScopeId(boolean genScopeValue) {
+        _getScope = genScopeValue;
+    }
+
+    /**
      * Boolean indicating that the script container is supporting RunAtClient features.
      * @param runAtClient boolean flag indicating we are running at the client
      * @netui:attribute required="false" rtexprvalue="true" type="boolean"
@@ -282,6 +296,12 @@
     public int doStartTag()
             throws JspException
     {
+        // check to see if we are generating unique names
+        if (_scopeId == null && _getScope) {
+            int id = getNextId((HttpServletRequest) pageContext.getRequest());
+            _scopeId = "n" + Integer.toString(id);        
+        }
+
         // if there is a scopeId, then we need to create a div to contains everything
         if (_scopeId != null) {
             write("<div");
@@ -515,6 +535,7 @@
         _runAtClient = false;
         _writeScript = false;
         _writeInitScript = false;
+        _getScope = false;
 
         if (_funcBlocks != null)
             _funcBlocks.clear();

Added: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/Controller.jpf
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/Controller.jpf?view=auto&rev=124237
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/Controller.jpf
Wed Jan  5 10:19:19 2005
@@ -0,0 +1,139 @@
+package idmap.genScopeId;
+
+import javax.servlet.http.HttpSession;
+import org.apache.beehive.netui.pageflow.FormData;
+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.
+ */
+@Jpf.Controller
+public class Controller extends PageFlowController
+{
+    private String[] _selectOptions = {"Option 1", "Option 2", "Option 3", "Option 4"};
+    private Bean _bean = new Bean();
+
+    public Bean getBean() {
+        return _bean;
+    }
+
+    public String[] getSelectOptions() {
+        return _selectOptions;
+    }
+    
+    @Jpf.Action(
+        forwards={
+           @Jpf.Forward(name="index", path="index.jsp")
+        }
+    )
+    protected Forward begin()
+    {
+        return new Forward("index");
+    }
+
+
+    /**
+     * Callback that is invoked when this controller instance is created.
+     */
+    protected void onCreate()
+    {
+    }
+
+    /**
+     * Callback that is invoked when this controller instance is destroyed.
+     */
+    protected void onDestroy(HttpSession session)
+    {
+    }
+
+
+    @Jpf.Action(forwards = {
+        @Jpf.Forward(name = "success",
+                     path = "index.jsp")
+    })
+    protected Forward postForm(Bean form)
+    {
+        _bean = form;
+        Forward forward = new Forward("success");
+        return forward;
+    }
+
+    public static class Bean extends FormData
+    {
+        private String text1;
+
+        private String text2;
+
+        private String text3;
+
+        private boolean check1;
+
+        private boolean check2;
+
+        public String getText1()
+        {
+            return text1;
+        }
+
+        public void setText1(String value)
+        {
+            text1 = value;
+        }
+
+        public String getText2()
+        {
+            return text2;
+        }
+
+        public void setText2(String value)
+        {
+            text2 = value;
+        }
+
+        public String getText3()
+        {
+            return text3;
+        }
+
+        public void setText3(String value)
+        {
+            text3 = value;
+        }
+
+        public boolean isCheck1()
+        {
+            return check1;
+        }
+
+        public void setCheck1(boolean value)
+        {
+            check1 = value;
+        }
+
+        public boolean isCheck2()
+        {
+            return check2;
+        }
+
+        public void setCheck2(boolean value)
+        {
+            check2 = value;
+        }
+    }
+}
+
+@Jpf.ViewProperties(value= {"<!-- This data is auto-generated. Hand-editing this section
is not recommended. -->",
+"<view-properties>",
+"<pageflow-object id='pageflow:/idmap/simple/Controller.jpf'/>",
+"<pageflow-object id='page:index.jsp'><property value='220' name='x'/><property
value='100' name='y'/></pageflow-object>",
+"<pageflow-object id='formbean:Bean'/>",
+"<pageflow-object id='action:postForm.do#idmap.simple.Controller.Bean'><property
name='x' value='340'/><property name='y' value='100'/></pageflow-object>",
+"<pageflow-object id='forward:path#success#index.jsp#@action:postForm.do#idmap.simple.Controller.Bean@'/>",
+"<pageflow-object id='action-call:@page:index.jsp@#@action:postForm.do#idmap.simple.Controller.Bean@'><property
name='elbowsX' value='256,280,280,304'/><property name='elbowsY' value='92,92,92,92'/><property
name='fromPort' value='East_1'/><property name='toPort' value='West_1'/></pageflow-object>",
+"<pageflow-object id='action:begin.do'><property value='80' name='x'/><property
value='100' name='y'/></pageflow-object>",
+"<pageflow-object id='forward:path#index#index.jsp#@action: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>",
+"</view-properties>"
+})
+interface VIEW_PROPERTIES { }

Added: incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/index.jsp
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/index.jsp?view=auto&rev=124237
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/idmap/genScopeId/index.jsp	Wed
Jan  5 10:19:19 2005
@@ -0,0 +1,55 @@
+<%@ 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 generateScopeId="true">
+    <head>
+        <netui:base/>
+    </head>
+    <netui:body>
+        <p style="color: green">This will test the autogeneration of scope
+	id's on both the HTML and ScriptContainer tags.  Below, JavaScript will
+	perform a search using the built in methods to find a checkbox.  The
+	result should never be null.
+        </p>
+        <netui:scriptContainer generateScopeId="true">
+        <netui:form action="postForm">
+        <span id="scopeOneSpan" />
+            <table>
+                <tr valign="top">
+                    <td>Check1:</td>
+                    <td>
+                    <netui:checkBox tagId="check1" dataSource="actionForm.check1"></netui:checkBox>
+                    </td>
+                </tr>
+                <tr valign="top">
+                    <td>Check2:</td>
+                    <td>
+                    <netui:checkBox tagId="check2" dataSource="actionForm.check2"></netui:checkBox>
+                    </td>
+                </tr>
+            </table>
+            <br>
+            &nbsp;
+            <netui:button tagId="button" type="submit" value="postForm"/>
+        </netui:form>
+        </netui:scriptContainer>
+        <hr>
+        <p id="javaOut"></p>
+    </netui:body>
+    <script language="JavaScript" type="text/JavaScript">
+
+    var p = document.getElementById("javaOut");
+    var s = document.getElementById("scopeOneSpan");
+
+    var val = "<b>Document Access</b><br>";
+    val = val + "CheckBox 1 by id is null: <b>" +
+        (document.getElementById(lookupIdByTagId("check1",s)) == null) + "</b><br>";
+
+    p.innerHTML = val;
+    </script>
+</netui:html>
+
+  
\ No newline at end of file

Modified: incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml?view=diff&rev=124237&p1=incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml&r1=124236&p2=incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/config/testRecorder-tests.xml&r2=124237
==============================================================================
--- 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 Jan  5 10:19:19 2005
@@ -2871,6 +2871,20 @@
          </features>
       </test>
       <test>
+         <name>IdMapGenScopeId</name>
+         <description>Test of autogeneration of the scope id.</description>
+         <webapp>coreWeb</webapp>
+         <categories>
+            <category>bvt</category>
+            <category>tags</category>
+         </categories>
+         <features>
+            <feature>JavaScript</feature>
+            <feature>ScriptContainer</feature>
+            <feature>scopeId</feature>
+         </features>
+      </test>
+      <test>
          <name>IdMapId</name>
          <description>Simple test of IdMaps with HTML Controls.</description>
          <webapp>coreWeb</webapp>

Added: incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/IdMapGenScopeId.xml
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/IdMapGenScopeId.xml?view=auto&rev=124237
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/test/webapps/drt/testRecorder/tests/IdMapGenScopeId.xml
Wed Jan  5 10:19:19 2005
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ses:recorderSession xmlns:ses="http://beehive.apache.org/netui/tools/testrecorder/2004/session">
+   <ses:sessionName>IdMapGenScopeId</ses:sessionName>
+   <ses:tester>Daryl</ses:tester>
+   <ses:startDate>05 Jan 2005, 09:54:52.746 AM MST</ses:startDate>
+   <ses:description>Test the autogeneration of scope ids</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/idmap/genScopeId/Controller.jpf</ses:uri>
+            <ses:method>GET</ses:method>
+            <ses:parameters/>
+            <ses:cookies>
+               <ses:cookie>
+                  <ses:name>JSESSIONID</ses:name>
+                  <ses:value>A931AC4C1DC4714FBACAC55CA05E301F</ses:value>
+               </ses:cookie>
+            </ses:cookies>
+            <ses:headers>
+               <ses:header>
+                  <ses:name>accept</ses:name>
+                  <ses:value>text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>accept-charset</ses:name>
+                  <ses:value>ISO-8859-1,utf-8;q=0.7,*;q=0.7</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,en;q=0.5</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=A931AC4C1DC4714FBACAC55CA05E301F</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>host</ses:name>
+                  <ses:value>localhost:8080</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>keep-alive</ses:name>
+                  <ses:value>300</ses:value>
+               </ses:header>
+               <ses:header>
+                  <ses:name>user-agent</ses:name>
+                  <ses:value>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5)
Gecko/20041107 Firefox/1.0</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;div scopeId="n0" >
+    &lt;head>
+        &lt;base href="http://localhost:8080/coreWeb/idmap/genScopeId/index.jsp">
+    &lt;/head>
+    &lt;body>
+        &lt;p style="color: green">This will test the autogeneration of scope
+	id's on both the HTML and ScriptContainer tags.  Below, JavaScript will
+	perform a search using the built in methods to find a checkbox.  The
+	result should never be null.
+        &lt;/p>
+        &lt;div scopeId="n1" >
+        &lt;form name="bean" action="/coreWeb/idmap/genScopeId/postForm.do" method="post">
+        &lt;span id="scopeOneSpan" />
+            &lt;table>
+                &lt;tr valign="top">
+                    &lt;td>Check1:&lt;/td>
+                    &lt;td>
+                    &lt;input type="hidden" name="wlw-checkbox_key:{actionForm.check1}OldValue"
value="false">&lt;input type="checkbox" name="wlw-checkbox_key:{actionForm.check1}"
id="n0.n1.check1">
+                    &lt;/td>
+                &lt;/tr>
+                &lt;tr valign="top">
+                    &lt;td>Check2:&lt;/td>
+                    &lt;td>
+                    &lt;input type="hidden" name="wlw-checkbox_key:{actionForm.check2}OldValue"
value="false">&lt;input type="checkbox" name="wlw-checkbox_key:{actionForm.check2}"
id="n0.n1.check2">
+                    &lt;/td>
+                &lt;/tr>
+            &lt;/table>
+            &lt;br>
+            &amp;nbsp;
+            &lt;input type="submit" id="n0.n1.button" value="postForm">
+        &lt;/form>
+        &lt;/div>
+
+&lt;script language="JavaScript" type="text/JavaScript">
+&lt;!--
+
+// **** This section contains code that will run when the page is loaded ****
+
+
+// Build the netui_names table to map the tagId attributes
+// to the real id written into the HTML
+if (netui_names == null)
+   var netui_names = new Object();
+netui_names.n1__check1="wlw-checkbox_key:{actionForm.check1}"
+netui_names.n1__check2="wlw-checkbox_key:{actionForm.check2}"
+netui_names.n1__button="n0.n1.button"
+
+
+// Build the netui_names table to map the tagId attributes
+// to the real id written into the HTML
+if (netui_tagIdMap == null)
+   var netui_tagIdMap = new Object();
+netui_tagIdMap.n1__check1="n0.n1.check1"
+netui_tagIdMap.n1__check2="n0.n1.check2"
+netui_tagIdMap.n1__button="n0.n1.button"
+
+
+// Build the netui_names table to map the tagId attributes
+// to the real id written into the HTML
+if (netui_tagIdNameMap == null)
+   var netui_tagIdNameMap = new Object();
+netui_tagIdNameMap.n1__check1="wlw-checkbox_key:{actionForm.check1}"
+netui_tagIdNameMap.n1__check2="wlw-checkbox_key:{actionForm.check2}"
+
+
+// **** This section contains functions typically run as events ****
+
+
+// method which will return a real id for a tagId,
+// the tag parameter will be used to find the scopeId for
+// containers that may scope their ids
+function getNetuiTagName(id, tag)
+{
+   var scopeId = getScopeId(tag);
+   if (scopeId == "")
+      return netui_names[id];
+   else
+      return netui_names[scopeId  + "__" + id];
+}
+
+// lookup by tagId to "real id"
+function lookupIdByTagId(id, tag)
+{
+   var scopeId = getScopeId(tag);
+   if (scopeId == "")
+      return netui_tagIdMap[id];
+   else
+      return netui_tagIdMap[scopeId  + "__" + id];
+}
+
+// lookup by tagId to "real name"
+function lookupNameByTagId(id, tag)
+{
+   var scopeId = getScopeId(tag);
+   if (scopeId == "")
+      return netui_tagIdNameMap[id];
+   else
+      return netui_tagIdNameMap[scopeId  + "__" + id];
+}
+
+// This method will walk the hierarchy from the pass element looking for a scopeId.
+// The first scopeId found will be returned or the empty string if a scopeId is not found.
+function getScopeId(tag)
+{
+   if (tag == null || tag.getAttribute == null)
+      return "";
+   var attrVal = tag.getAttribute("scopeId");
+   if (attrVal != null)
+      return attrVal;
+   return getScopeId(tag.parentNode);
+}
+-->
+&lt;/script>
+
+
+        &lt;hr>
+        &lt;p id="javaOut">&lt;/p>
+    &lt;/body>
+    &lt;script language="JavaScript" type="text/JavaScript">
+
+    var p = document.getElementById("javaOut");
+    var s = document.getElementById("scopeOneSpan");
+
+    var val = "&lt;b>Document Access&lt;/b>&lt;br>";
+    val = val + "CheckBox 1 by id is null: &lt;b>" +
+        (document.getElementById(lookupIdByTagId("check1",s)) == null) + "&lt;/b>&lt;br>";
+
+    p.innerHTML = val;
+    &lt;/script>
+&lt;/div>
+&lt;/html></ses:responseBody>
+         </ses:response>
+      </ses:test>
+   </ses:tests>
+   <ses:endDate>05 Jan 2005, 09:55:07.207 AM MST</ses:endDate>
+   <ses:testCount>1</ses:testCount>
+</ses:recorderSession>
\ No newline at end of file

Mime
View raw message