tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1155178 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/alerts/ main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/services/ajax/ main/java/org/apache/tapestr...
Date Tue, 09 Aug 2011 00:56:37 GMT
Author: hlship
Date: Tue Aug  9 00:56:37 2011
New Revision: 1155178

URL: http://svn.apache.org/viewvc?rev=1155178&view=rev
Log:
TAP5-1598: AlertManager service does the wrong thing if the Ajax request will terminate with
a redirect

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/alerts/AlertManagerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/MultiZoneUpdateEventResultProcessor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Environment.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/alerts/AlertManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/alerts/AlertManagerImpl.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/alerts/AlertManagerImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/alerts/AlertManagerImpl.java
Tue Aug  9 00:56:37 2011
@@ -15,6 +15,8 @@
 package org.apache.tapestry5.internal.alerts;
 
 import org.apache.tapestry5.alerts.*;
+import org.apache.tapestry5.ioc.services.PerThreadValue;
+import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.services.ApplicationStateManager;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
@@ -29,11 +31,15 @@ public class AlertManagerImpl implements
 
     private final AjaxResponseRenderer ajaxResponseRenderer;
 
-    public AlertManagerImpl(ApplicationStateManager asm, Request request, AjaxResponseRenderer
ajaxResponseRenderer)
+    private final PerThreadValue<Boolean> needAlertStorageCleanup;
+
+    public AlertManagerImpl(ApplicationStateManager asm, Request request, AjaxResponseRenderer
ajaxResponseRenderer, PerthreadManager perThreadManager)
     {
         this.asm = asm;
         this.request = request;
         this.ajaxResponseRenderer = ajaxResponseRenderer;
+
+        needAlertStorageCleanup = perThreadManager.createValue();
     }
 
     public void info(String message)
@@ -55,27 +61,56 @@ public class AlertManagerImpl implements
     {
         final Alert alert = new Alert(duration, severity, message);
 
-        boolean ajax = request.isXHR();
+        if (request.isXHR())
+        {
+            addCallbackForAlert(alert);
+        }
+
+        // Add it to the storage; this is always done, even in an Ajax request, because we
may end up
+        // redirecting to a new page, rather than doing a partial page update on the current
page ... in which
+        // case we need the alerts stored persistently until we render the new page.
 
-        if (ajax)
+        getAlertStorage().add(alert);
+    }
+
+    private void addCallbackForAlert(final Alert alert)
+    {
+        ajaxResponseRenderer.addCallback(new JavaScriptCallback()
+        {
+            public void run(JavaScriptSupport javascriptSupport)
+            {
+                javascriptSupport.addInitializerCall("addAlert", alert.toJSON());
+            }
+        });
+
+        addAlertStorageCleanupCallback();
+    }
+
+    private void addAlertStorageCleanupCallback()
+    {
+        // Add a callback that exists just to clear the non-persistent alerts.
+        // Only one of these is needed.
+
+        if (needAlertStorageCleanup.get(true))
         {
             ajaxResponseRenderer.addCallback(new JavaScriptCallback()
             {
                 public void run(JavaScriptSupport javascriptSupport)
                 {
-                    javascriptSupport.addInitializerCall("addAlert", alert.toJSON());
+                    // In an Ajax request, the Alerts are added, just so that they can be
removed if not persistent.
+                    // Again, this is for the rare case where there's a redirect to another
page.
+
+                    getAlertStorage().dismissNonPersistent();
                 }
             });
-        }
 
-        // In Ajax mode, ony persistent alerts need to be stored for later requests (so that
they can
-        // be re-presented until explicitly dismissed). In traditional mode, the alerts are
added here
-        // to the AlertStorage and then later, during the render, the Alerts component will
take
-        // care of JavaScript initialization for them.
-        if (!ajax || duration.persistent)
-        {
-            asm.get(AlertStorage.class).add(alert);
+            needAlertStorageCleanup.set(false);
         }
     }
 
+    private AlertStorage getAlertStorage()
+    {
+        return asm.get(AlertStorage.class);
+    }
+
 }
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxComponentEventRequestHandler.java
Tue Aug  9 00:56:37 2011
@@ -14,9 +14,8 @@
 
 package org.apache.tapestry5.internal.services;
 
-import org.apache.tapestry5.TrackableComponentEventCallback;
 import org.apache.tapestry5.ContentType;
-import org.apache.tapestry5.EventConstants;
+import org.apache.tapestry5.TrackableComponentEventCallback;
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.structure.ComponentPageElement;
 import org.apache.tapestry5.internal.structure.Page;
@@ -52,8 +51,8 @@ public class AjaxComponentEventRequestHa
 
     public AjaxComponentEventRequestHandler(RequestPageCache cache, Request request, PageRenderQueue
queue, @Ajax
     ComponentEventResultProcessor resultProcessor, PageActivator pageActivator,
-            PageContentTypeAnalyzer pageContentTypeAnalyzer, Environment environment,
-            AjaxPartialResponseRenderer partialRenderer)
+                                            PageContentTypeAnalyzer pageContentTypeAnalyzer,
Environment environment,
+                                            AjaxPartialResponseRenderer partialRenderer)
     {
         this.cache = cache;
         this.queue = queue;
@@ -118,19 +117,19 @@ public class AjaxComponentEventRequestHa
         environment.pop(TrackableComponentEventCallback.class);
         environment.pop(ComponentEventResultProcessor.class);
 
-        if (queue.isPartialRenderInitialized())
+
+        // If the result processor was passed a value, then it will already have rendered.
Otherise it was not passed a value,
+        // but it's still possible that we still want to do a partial page render ... if
filters were added to the render queue.
+        // In that event, run the partial page render now and return.
+
+        if ((!resultProcessorInvoked.get()) && queue.isPartialRenderInitialized())
         {
             partialRenderer.renderPartialPageMarkup();
             return;
         }
 
-        // If some other form of return value that's not a partial page render was send through
to the
-        // Ajax ComponentEventResultProcessor, then there's nothing more to do.
-
-        if (resultProcessorInvoked.get())
-            return;
-
         // Send an empty JSON reply if no value was returned from the component event handler
method.
+        // This is the typical behavior when an Ajax component event handler returns null.
 
         JSONObject reply = new JSONObject();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AjaxPartialResponseRendererImpl.java
Tue Aug  9 00:56:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -21,10 +21,7 @@ import org.apache.tapestry5.internal.Int
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.json.JSONObject;
-import org.apache.tapestry5.services.MarkupWriterFactory;
-import org.apache.tapestry5.services.PartialMarkupRenderer;
-import org.apache.tapestry5.services.Request;
-import org.apache.tapestry5.services.Response;
+import org.apache.tapestry5.services.*;
 
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -43,20 +40,22 @@ public class AjaxPartialResponseRenderer
 
     private final boolean compactJSON;
 
+    private final Environment environment;
+
     public AjaxPartialResponseRendererImpl(MarkupWriterFactory factory,
 
-    Request request,
+                                           Request request,
 
-    Response response,
+                                           Response response,
 
-    PartialMarkupRenderer partialMarkupRenderer,
+                                           PartialMarkupRenderer partialMarkupRenderer,
 
-    @Inject
-    @Symbol(SymbolConstants.CHARSET)
-    String outputEncoding,
+                                           @Inject
+                                           @Symbol(SymbolConstants.CHARSET)
+                                           String outputEncoding,
 
-    @Symbol(SymbolConstants.COMPACT_JSON)
-    boolean compactJSON)
+                                           @Symbol(SymbolConstants.COMPACT_JSON)
+                                           boolean compactJSON, Environment environment)
     {
         this.factory = factory;
         this.request = request;
@@ -64,10 +63,13 @@ public class AjaxPartialResponseRenderer
         this.partialMarkupRenderer = partialMarkupRenderer;
         this.outputEncoding = outputEncoding;
         this.compactJSON = compactJSON;
+        this.environment = environment;
     }
 
     public void renderPartialPageMarkup() throws IOException
     {
+        environment.cloak();
+
         // This is a complex area as we are trying to keep public and private services properly
         // separated, and trying to keep stateless and stateful (i.e., perthread scope) services
         // separated. So we inform the stateful queue service what it needs to do here ...
@@ -89,5 +91,7 @@ public class AjaxPartialResponseRenderer
         reply.print(pw, compactJSON);
 
         pw.close();
+
+        environment.decloak();
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EnvironmentImpl.java
Tue Aug  9 00:56:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2011` The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,15 +14,16 @@
 
 package org.apache.tapestry5.internal.services;
 
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.OneShotLock;
 import org.apache.tapestry5.ioc.services.ThreadCleanupListener;
+import org.apache.tapestry5.ioc.util.Stack;
 import org.apache.tapestry5.services.Environment;
 
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * A non-threadsafe implementation (expects to use the "perthread" service lifecyle).
  */
@@ -32,7 +33,13 @@ public class EnvironmentImpl implements 
     // My generics mojo breaks down when we talk about the key and the value being related
     // types.
 
-    private final Map<Class, LinkedList> typeToStack = CollectionFactory.newMap();
+    private Map<Class, LinkedList> typeToStack = CollectionFactory.newMap();
+
+    // Support for cloak/decloak.  Cloaking pushes the current typeToStack map onto the stack
+    // and creates a new, empyt, Map to replace it. Decloaking discards the current map
+    // and replaces it with the top map on the stack.
+
+    private final Stack<Map<Class, LinkedList>> cloakStack = CollectionFactory.newStack();
 
     private final OneShotLock lock = new OneShotLock();
 
@@ -100,13 +107,23 @@ public class EnvironmentImpl implements 
 
     public void clear()
     {
-        lock.check();
-
-        typeToStack.clear();
+        throw new IllegalStateException("Environment.clear() is no longer supported.");
     }
 
     public void threadDidCleanup()
     {
         lock.lock();
     }
+
+    public void cloak()
+    {
+        cloakStack.push(typeToStack);
+
+        typeToStack = CollectionFactory.newMap();
+    }
+
+    public void decloak()
+    {
+        typeToStack = cloakStack.pop();
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PageRenderQueueImpl.java
Tue Aug  9 00:56:37 2011
@@ -23,6 +23,7 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.ioc.util.Stack;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.runtime.RenderCommand;
+import org.apache.tapestry5.runtime.RenderQueue;
 import org.apache.tapestry5.services.PartialMarkupRenderer;
 import org.apache.tapestry5.services.PartialMarkupRendererFilter;
 import org.slf4j.Logger;
@@ -35,6 +36,14 @@ import org.slf4j.Logger;
 @Scope(ScopeConstants.PERTHREAD)
 public class PageRenderQueueImpl implements PageRenderQueue
 {
+    public static final RenderCommand NOOP_RENDER_COMMAND = new RenderCommand()
+    {
+        public void render(MarkupWriter writer, RenderQueue queue)
+        {
+            // Do nothing. The command is just to let the filters do their thing.
+        }
+    };
+
     private final LoggerSource loggerSource;
 
     private Page page;
@@ -88,6 +97,11 @@ public class PageRenderQueueImpl impleme
     public void forcePartialRenderInitialized()
     {
         partialRenderInitialized = true;
+
+        if (rootCommand == null)
+        {
+            rootCommand = NOOP_RENDER_COMMAND;
+        }
     }
 
     public void initializeForPartialPageRender(RenderCommand rootCommand)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderCommandComponentEventResultProcessor.java
Tue Aug  9 00:56:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -14,8 +14,6 @@
 
 package org.apache.tapestry5.internal.services;
 
-import java.io.IOException;
-
 import org.apache.tapestry5.MarkupWriter;
 import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.internal.services.ajax.AjaxFormUpdateController;
@@ -25,10 +23,12 @@ import org.apache.tapestry5.services.Com
 import org.apache.tapestry5.services.PartialMarkupRenderer;
 import org.apache.tapestry5.services.PartialMarkupRendererFilter;
 
+import java.io.IOException;
+
 /**
  * Processor for objects that implement {@link RenderCommand} (such as
- * {@link org.apache.tapestry5.internal.structure.BlockImpl}).
- * 
+ * {@link org.apache.tapestry5.internal.structure.BlockImpl}), used with an Ajax component
event.
+ *
  * @see AjaxPartialResponseRenderer#renderPartialPageMarkup()
  */
 public class RenderCommandComponentEventResultProcessor implements ComponentEventResultProcessor<RenderCommand>,
@@ -38,17 +38,24 @@ public class RenderCommandComponentEvent
 
     private final AjaxFormUpdateController ajaxFormUpdateController;
 
+    private final AjaxPartialResponseRenderer partialRenderer;
+
     public RenderCommandComponentEventResultProcessor(PageRenderQueue pageRenderQueue,
-            AjaxFormUpdateController ajaxFormUpdateController)
+                                                      AjaxFormUpdateController ajaxFormUpdateController,
AjaxPartialResponseRenderer partialRenderer)
     {
         this.pageRenderQueue = pageRenderQueue;
         this.ajaxFormUpdateController = ajaxFormUpdateController;
+        this.partialRenderer = partialRenderer;
     }
 
-    public void processResultValue(final RenderCommand value) throws IOException
+    public void processResultValue(RenderCommand value) throws IOException
     {
         pageRenderQueue.addPartialMarkupRendererFilter(this);
         pageRenderQueue.initializeForPartialPageRender(value);
+
+        // And render the content right now.
+
+        partialRenderer.renderPartialPageMarkup();
     }
 
     /**
@@ -56,7 +63,7 @@ public class RenderCommandComponentEvent
      * <ul>
      * <li>It creates an outer element to capture the partial page content that will
be rendered</li>
      * <li>It does setup and cleanup with the {@link AjaxFormUpdateController}</li>
-     * <li>It extracts the child markup and stuff it into the reply's "content" property.</li>
+     * <li>It extracts the child markup and stuffs it into the reply's "content" property.</li>
      * </ul>
      */
     public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer
renderer)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
Tue Aug  9 00:56:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -36,18 +36,18 @@ import org.apache.tapestry5.services.Str
  */
 public class StreamPageContentResultProcessor implements ComponentEventResultProcessor<StreamPageContent>
 {
+    private final PageRenderRequestHandler handler;
 
-    @Inject
-    private PageRenderRequestHandler handler;
+    private final ComponentClassResolver resolver;
 
-    @Inject
-    private ComponentClassResolver resolver;
+    private final TypeCoercer typeCoercer;
 
-    @Inject
-    private TypeCoercer typeCoercer;
-
-    @Inject
-    private Request request;
+    public StreamPageContentResultProcessor(PageRenderRequestHandler handler, ComponentClassResolver
resolver, TypeCoercer typeCoercer)
+    {
+        this.handler = handler;
+        this.resolver = resolver;
+        this.typeCoercer = typeCoercer;
+    }
 
     public void processResultValue(final StreamPageContent value) throws IOException
     {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/AjaxResponseRendererImpl.java
Tue Aug  9 00:56:37 2011
@@ -39,6 +39,9 @@ public class AjaxResponseRendererImpl im
 
         RenderCommand command = typeCoercer.coerce(renderer, RenderCommand.class);
 
+        // When a filter is added, it is assumed that some partial render will occur. This
covers the case where
+        // a MultiZoneUpdate or a null is returned from the Ajax event handler method.
+
         queue.forcePartialRenderInitialized();
         queue.addPartialMarkupRendererFilter(new SingleZonePartialRendererFilter(clientId,
command, queue, ajaxFormUpdateController));
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/MultiZoneUpdateEventResultProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/MultiZoneUpdateEventResultProcessor.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/MultiZoneUpdateEventResultProcessor.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/MultiZoneUpdateEventResultProcessor.java
Tue Aug  9 00:56:37 2011
@@ -15,6 +15,7 @@
 package org.apache.tapestry5.internal.services.ajax;
 
 import org.apache.tapestry5.ajax.MultiZoneUpdate;
+import org.apache.tapestry5.internal.services.AjaxPartialResponseRenderer;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.runtime.RenderCommand;
@@ -42,10 +43,13 @@ public class MultiZoneUpdateEventResultP
 
     private final AjaxResponseRenderer ajaxResponseRenderer;
 
-    public MultiZoneUpdateEventResultProcessor(TypeCoercer typeCoercer, AjaxResponseRenderer
ajaxResponseRenderer)
+    private final AjaxPartialResponseRenderer partialRenderer;
+
+    public MultiZoneUpdateEventResultProcessor(TypeCoercer typeCoercer, AjaxResponseRenderer
ajaxResponseRenderer, AjaxPartialResponseRenderer partialRenderer)
     {
         this.typeCoercer = typeCoercer;
         this.ajaxResponseRenderer = ajaxResponseRenderer;
+        this.partialRenderer = partialRenderer;
     }
 
     public void processResultValue(final MultiZoneUpdate value) throws IOException
@@ -65,6 +69,8 @@ public class MultiZoneUpdateEventResultP
 
             ajaxResponseRenderer.addRender(zoneId, zoneRenderCommand);
         }
+
+        partialRenderer.renderPartialPageMarkup();
     }
 
     private RenderCommand toRenderer(String zoneId, Object provided)

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Environment.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Environment.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Environment.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/Environment.java
Tue Aug  9 00:56:37 2011
@@ -69,7 +69,24 @@ public interface Environment
     <T> T push(Class<T> type, T instance);
 
     /**
-     * Clears all stacks; used when initializing the Environment before a render.
+     * Clears all stacks; no longer used by Tapestry.
+     *
+     * @deprecated Deprecated in 5.3 with no replacement.
      */
     void clear();
+
+    /**
+     * Hides all current environment values, making the Environment object appear empty,
until
+     * a call to {@link #decloak()}} restores the original state.
+     *
+     * @since 5.3
+     */
+    void cloak();
+
+    /**
+     * Restores state previously hidden by {@link #cloak()}}.
+     *
+     * @since 5.3
+     */
+    void decloak();
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy
Tue Aug  9 00:56:37 2011
@@ -73,4 +73,23 @@ class AlertsTests extends SeleniumTestCa
         assertText "css=.t-alert-container", ""
     }
 
+    @Test
+    void ajax_update_with_redirect() {
+
+        openLinks "Alerts Demo", "reset"
+
+        select "css=#ajax select[name=\"severity\"]", "Error"
+        select "css=#ajax select[name=\"duration\"]", "Single"
+        type "css=#ajax input[name=\"message\"]", "ajax error single"
+        check "css=#ajax input[type='checkbox']"
+
+        click "//input[@value='Ajax Update']"
+
+        sleep 100
+
+        assertTextPresent "ajax error single"
+
+        click "link=Dismiss all"
+    }
+
 }
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AlertsDemo.java
Tue Aug  9 00:56:37 2011
@@ -38,6 +38,9 @@ public class AlertsDemo
     @SessionState
     private AlertStorage storage;
 
+    @Property
+    private boolean redirectToIndex;
+
     void onSuccessFromTraditional()
     {
         alertManager.info("Traditional form submission");
@@ -49,6 +52,11 @@ public class AlertsDemo
         alertManager.info("Ajax form submission");
         alertManager.alert(duration, severity, message);
 
+        if (redirectToIndex)
+        {
+            return Index.class;
+        }
+
         return formZone.getBody();
     }
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/EnvironmentImplTest.java
Tue Aug  9 00:56:37 2011
@@ -62,19 +62,15 @@ public class EnvironmentImplTest extends
     public void clear()
     {
         Environment e = new EnvironmentImpl();
-        Runnable r1 = mockRunnable();
-        Runnable r2 = mockRunnable();
 
-        replay();
-
-        e.push(Runnable.class, r1);
-        e.push(Runnable.class, r2);
-
-        e.clear();
-
-        assertNull(e.peek(Runnable.class));
-
-        verify();
+        try
+        {
+            e.clear();
+            unreachable();
+        } catch (IllegalStateException ex)
+        {
+            assertMessageContains(ex, "no longer supported");
+        }
     }
 
     @Test
@@ -86,8 +82,7 @@ public class EnvironmentImplTest extends
         {
             e.pop(Runnable.class);
             unreachable();
-        }
-        catch (NoSuchElementException ex)
+        } catch (NoSuchElementException ex)
         {
         }
     }
@@ -123,8 +118,7 @@ public class EnvironmentImplTest extends
         {
             e.peekRequired(List.class);
             unreachable();
-        }
-        catch (RuntimeException ex)
+        } catch (RuntimeException ex)
         {
             assertEquals(
                     ex.getMessage(),

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml?rev=1155178&r1=1155177&r2=1155178&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/AlertsDemo.tml
Tue Aug  9 00:56:37 2011
@@ -6,7 +6,7 @@
 
 <div id="traditional">
 
-    <t:beaneditform t:id="traditional" object="this" submitLabel="Traditional Update"/>
+    <t:beaneditform t:id="traditional" object="this" exclude="redirectToIndex" submitLabel="Traditional
Update"/>
 </div>
 
 <h2>Ajax Form</h2>



Mime
View raw message