Author: dolander
Date: Wed Mar 30 12:17:55 2005
New Revision: 159519

URL: http://svn.apache.org/viewcvs?view=rev&rev=159519
Log:
Jira 480 -- Tag files didn't work correctly with ScriptContainers.  The
reason for this was that the id was generated by walking to tag hierarchy.
For Tag files, they can't walk out of the tag hiearchy and find ScriptContainers
they are contained in.  This fix moves the naming into the request so that we
no longer walk the tag hiearchy.


Modified:
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
    
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
    
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/javascript/ScriptContainer.java

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java?view=diff&r1=159518&r2=159519
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractClassicTag.java
 Wed Mar 30 12:17:55 2005
@@ -30,6 +30,7 @@
 import org.apache.struts.util.RequestUtils;
 
 import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.PageContext;
@@ -37,10 +38,7 @@
 import javax.servlet.jsp.tagext.SimpleTagSupport;
 import javax.servlet.jsp.tagext.Tag;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
 
 /**
  * AbstractBaseTag is the base tag for most of the NetUI tags.  This tag 
provides default behavior
@@ -265,6 +263,22 @@
      */
     final protected String getIdForTagId(String tagId)
     {
+        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
+        ArrayList<String> list = (ArrayList<String>)
+                
org.apache.beehive.netui.tags.RequestUtils.getOuterAttribute(req,
+                        ScriptContainer.SCOPE_ID);
+        if (list == null)
+            return tagId;
+        StringBuilder sb = new StringBuilder();
+        for (int i=0;i<list.size();i++) {
+            sb.append(list.get(i));
+            sb.append('.');
+        }
+        sb.append(tagId);
+        return sb.toString();
+
+
+        /*
         Tag tag = this;
         while (tag != null) {
             if (tag instanceof ScriptContainer) {
@@ -276,6 +290,7 @@
             tag = tag.getParent();
         }
         return tagId;
+        */
     }
 
     ///////////////////////////  Generic Attribute Setting Support  
////////////////////////////

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java?view=diff&r1=159518&r2=159519
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/AbstractSimpleTag.java
 Wed Mar 30 12:17:55 2005
@@ -11,6 +11,7 @@
 import org.apache.struts.util.RequestUtils;
 
 import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspContext;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.JspWriter;
@@ -20,6 +21,7 @@
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Locale;
+import java.util.ArrayList;
 
 /**
  * @netui:tag
@@ -255,19 +257,18 @@
      */
     final protected String getIdForTagId(String tagId)
     {
-        JspTag tag = this;
-        while (tag != null) {
-            if (tag instanceof ScriptContainer) {
-                String sid = ((ScriptContainer) tag).getIdScope();
-                if (sid != null) {
-                    tagId = sid + "." + tagId;
-                }
-            }
-            if (tag instanceof Tag)
-                tag = ((Tag) tag).getParent();
-            else
-                tag = ((SimpleTag) tag).getParent();
+        HttpServletRequest req = (HttpServletRequest) 
getPageContext().getRequest();
+        ArrayList<String> list = (ArrayList<String>)
+                
org.apache.beehive.netui.tags.RequestUtils.getOuterAttribute(req,
+                        ScriptContainer.SCOPE_ID);
+        if (list == null)
+            return tagId;
+        StringBuilder sb = new StringBuilder();
+        for (int i=0;i<list.size();i++) {
+            sb.append(list.get(i));
+            sb.append('.');
         }
-        return tagId;
+        sb.append(tagId);
+        return sb.toString();
     }
 }

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&r1=159518&r2=159519
==============================================================================
--- 
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 Mar 30 12:17:55 2005
@@ -223,6 +223,7 @@
         // write out the html...
         _state.lang = currentLocale.getLanguage();
         String idScope = getRealIdScope();
+        pushIdScope();
         if (idScope != null) {
             _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, 
"netui:idScope", idScope);
         }
@@ -241,6 +242,8 @@
      */
     public int doEndTag() throws JspException
     {
+        popIdScope();
+        
         // if there are errors then we should output the error table
         ErrorHandling.reportCollectedErrors(pageContext, this);
 

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java?view=diff&r1=159518&r2=159519
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/javascript/ScriptContainer.java
 Wed Mar 30 12:17:55 2005
@@ -19,6 +19,7 @@
 
 import org.apache.beehive.netui.tags.AbstractClassicTag;
 import org.apache.beehive.netui.tags.TagConfig;
+import org.apache.beehive.netui.tags.RequestUtils;
 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
 import org.apache.beehive.netui.tags.rendering.ScriptTag;
 import org.apache.beehive.netui.tags.rendering.TagRenderingBase;
@@ -72,6 +73,8 @@
 public class ScriptContainer extends AbstractClassicTag
         implements IScriptReporter
 {
+    public final static String SCOPE_ID = "netui:scopeId";
+
     private String _idScope = null;
     private ArrayList<String> _funcBlocks;
     private ArrayList<String> _codeBefore;
@@ -232,6 +235,7 @@
             throws JspException
     {
         String scope = getRealIdScope();
+        pushIdScope();
 
         WriteRenderAppender writer = new WriteRenderAppender(pageContext);
         writeBeforeBlocks(writer);
@@ -255,6 +259,9 @@
     public int doEndTag()
             throws JspException
     {
+
+        popIdScope();
+
         // writeout the script.
         WriteRenderAppender writer = new WriteRenderAppender(pageContext);
 
@@ -270,6 +277,30 @@
     }
 
     /////////////////////////////////// Protected Support 
////////////////////////////////////
+
+    protected void pushIdScope()
+    {
+        if (_idScope != null) {
+            HttpServletRequest req = (HttpServletRequest) 
pageContext.getRequest();
+            ArrayList<String> list = (ArrayList<String>) 
RequestUtils.getOuterAttribute(req,SCOPE_ID);
+            if (list == null) {
+                list = new ArrayList<String>();
+                RequestUtils.setOuterAttribute(req,SCOPE_ID,list);
+            }
+            list.add(_idScope);
+
+        }
+    }
+
+    protected void popIdScope()
+    {
+        if (_idScope != null) {
+            HttpServletRequest req = (HttpServletRequest) 
pageContext.getRequest();
+            ArrayList<String> list = (ArrayList<String>) 
RequestUtils.getOuterAttribute(req,SCOPE_ID);
+            assert(list != null);
+            list.remove(list.size() -1);
+        }
+    }
 
     /**
      * This method will return the real scope id for the script container.  It


Reply via email to