Revision: 1251
          http://stripes.svn.sourceforge.net/stripes/?rev=1251&view=rev
Author:   bengunter
Date:     2010-06-07 18:36:19 +0000 (Mon, 07 Jun 2010)

Log Message:
-----------
STS-391: Return SKIP_PAGE in LayoutRenderTag if it is the outer render tag, the 
one that started the whole render process. This prevents sending trailing junk 
following the closing tag. Also did some cleanup and simplification of the 
LayoutRenderTag code while fixing this little issue.

Modified Paths:
--------------
    
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java

Modified: 
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
===================================================================
--- 
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
  2010-05-25 12:58:06 UTC (rev 1250)
+++ 
branches/1.5.x/stripes/src/net/sourceforge/stripes/tag/layout/LayoutRenderTag.java
  2010-06-07 18:36:19 UTC (rev 1251)
@@ -15,7 +15,6 @@
 package net.sourceforge.stripes.tag.layout;
 
 import java.io.IOException;
-import java.util.LinkedList;
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.DynamicAttributes;
@@ -36,18 +35,8 @@
 
     private String name;
     private LayoutContext context;
-    private Boolean newContext;
-    private boolean silent;
+    private boolean contextIsNew, silent, outer;
 
-    /**
-     * True if this is the "outer" tag. That is, the render tag that kicks off 
the whole layout
-     * rendering process.
-     */
-    public boolean isOuterTag() {
-        LinkedList<LayoutContext> stack = LayoutContext.getStack(pageContext, 
false);
-        return stack != null && stack.size() < 2;
-    }
-
     /** Gets the name of the layout to be used. */
     public String getName() { return name; }
 
@@ -58,30 +47,21 @@
     public LayoutContext getContext() {
         if (context == null) {
             LayoutContext context = LayoutContext.lookup(pageContext);
-            boolean contextNew = false;
+            boolean contextIsNew = false;
 
             if (context == null || !context.isComponentRenderPhase()
                     || context.isComponentRenderPhase() && 
isChildOfComponent()) {
                 context = LayoutContext.push(this);
-                contextNew = true;
+                contextIsNew = true;
             }
 
             this.context = context;
-            this.newContext = contextNew;
+            this.contextIsNew = contextIsNew;
         }
 
         return context;
     }
 
-    /** True if the context returned by {...@link #getContext()} was newly 
created by this tag. */
-    public boolean isNewContext() {
-        // Force initialization of the context if necessary
-        if (newContext == null)
-            getContext();
-
-        return newContext;
-    }
-
     /** Used by the JSP container to provide the tag with dynamic attributes. 
*/
     public void setDynamicAttribute(String uri, String localName, Object 
value) throws JspException {
         getContext().getParameters().put(localName, value);
@@ -101,9 +81,10 @@
     @Override
     public int doStartTag() throws JspException {
         LayoutContext context = getContext();
+        outer = LayoutContext.getStack(pageContext, true).getFirst() == 
context;
         silent = context.getOut().isSilent();
 
-        if (isNewContext()) {
+        if (contextIsNew) {
             log.debug("Start layout init in ", context.getRenderPage());
             pushPageContextAttributes(context.getParameters());
         }
@@ -133,11 +114,11 @@
        public int doEndTag() throws JspException {
         try {
             LayoutContext context = getContext();
-            if (isNewContext()) {
+            if (contextIsNew) {
                 // Substitution of the layout writer for the regular JSP 
writer does not work for
                 // the initial render tag. Its body evaluation still uses the 
original JSP writer
                 // for output. Clear the output buffer before executing the 
definition page.
-                if (isOuterTag()) {
+                if (outer) {
                     try {
                         context.getOut().clear();
                     }
@@ -184,13 +165,15 @@
 
             // Restore output's silent flag
             context.getOut().setSilent(silent, pageContext);
+
+            // Skip the rest of the page if this is the outer-most render tag
+            return outer ? SKIP_PAGE : EVAL_PAGE;
         }
         finally {
             this.context = null;
-            this.newContext = null;
+            this.contextIsNew = false;
             this.silent = false;
+            this.outer = false;
         }
-
-        return EVAL_PAGE;
     }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to