Author: drobiazko
Date: Sat Jul 24 13:30:16 2010
New Revision: 978870

URL: http://svn.apache.org/viewvc?rev=978870&view=rev
Log:
TAP5-1015: Provide a new return type for event handler methods that would 
trigger the rendering of a particular page without a redirect

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java
   (with props)
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java

Added: 
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=978870&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
 Sat Jul 24 13:30:16 2010
@@ -0,0 +1,77 @@
+// Copyright 2010 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import java.io.IOException;
+
+import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.internal.EmptyEventContext;
+import org.apache.tapestry5.internal.InternalConstants;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
+import org.apache.tapestry5.services.ComponentClassResolver;
+import org.apache.tapestry5.services.ComponentEventResultProcessor;
+import org.apache.tapestry5.services.PageRenderRequestHandler;
+import org.apache.tapestry5.services.PageRenderRequestParameters;
+import org.apache.tapestry5.services.Request;
+import org.apache.tapestry5.services.StreamPageContent;
+
+/**
+ * Used to trigger the rendering of a particular page without causing a 
redirect to that page.
+ * The content of the page is just streamed to the client.
+ * 
+ * @since 5.2.0
+ */
+public class StreamPageContentResultProcessor implements 
ComponentEventResultProcessor<StreamPageContent>
+{
+
+    @Inject
+    private PageRenderRequestHandler handler;
+
+    @Inject
+    private ComponentClassResolver resolver;
+
+    @Inject
+    private TypeCoercer typeCoercer;
+    
+    @Inject
+    private Request request;
+
+    public void processResultValue(final StreamPageContent value) throws 
IOException
+    {
+
+        final Class<?> pageClass = value.getPageClass();
+        final Object[] activationContext = value.getPageActivationContext();
+
+        final String pageName = 
this.resolver.resolvePageClassNameToPageName(pageClass.getName());
+
+        final EventContext context = activationContext == null ? new 
EmptyEventContext()
+                : new ArrayEventContext(this.typeCoercer, activationContext);
+        
+        Object generatingRederedPage = 
request.getAttribute(InternalConstants.GENERATING_RENDERED_PAGE);
+
+        try
+        {
+            // This is needed otherwise PageMarkupRendererImpl would clear the 
environment
+            request.setAttribute(InternalConstants.GENERATING_RENDERED_PAGE, 
true);
+            
+            this.handler.handle(new PageRenderRequestParameters(pageName, 
context, false));
+        }
+        finally
+        {
+            request.setAttribute(InternalConstants.GENERATING_RENDERED_PAGE, 
generatingRederedPage);
+        }
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StreamPageContentResultProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java?rev=978870&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java
 Sat Jul 24 13:30:16 2010
@@ -0,0 +1,65 @@
+// Copyright 2010 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.services;
+
+/**
+ * An event handler method may return an instance of this class to trigger the 
rendering 
+ * of a particular page without causing a redirect to that page.
+ * 
+ * @since 5.2.0
+ *
+ */
+public final class StreamPageContent
+{
+    private final Class<?> pageClass;
+    private final Object[] pageActivationContext;
+
+    /**
+     * 
+     * @param pageClass class of the page to render
+     */
+    public StreamPageContent(final Class<?> pageClass)
+    {
+        this(pageClass, (Object[]) null);
+    }
+
+    /**
+     * 
+     * @param pageClass class of the page to render
+     * @param pageActivationContext activation context of the page
+     */
+    public StreamPageContent(final Class<?> pageClass, final Object... 
pageActivationContext)
+    {
+        super();
+        this.pageClass = pageClass;
+        this.pageActivationContext = pageActivationContext;
+    }
+
+    /**
+     * Returns the class of the page to render.
+     */
+    public Class<?> getPageClass()
+    {
+        return this.pageClass;
+    }
+
+    /**
+     * Returns the activation context of the page.
+     */
+    public Object[] getPageActivationContext()
+    {
+        return this.pageActivationContext;
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/StreamPageContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=978870&r1=978869&r2=978870&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 Sat Jul 24 13:30:16 2010
@@ -1790,6 +1790,8 @@ public final class TapestryModule
         configuration.add(Component.class, componentInstanceProcessor);
 
         configuration.addInstance(StreamResponse.class, 
StreamResponseResultProcessor.class);
+
+        configuration.addInstance(StreamPageContent.class, 
StreamPageContentResultProcessor.class);
     }
 
     /**

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml?rev=978870&r1=978869&r2=978870&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml 
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ReturnTypes.tml Sat 
Jul 24 13:30:16 2010
@@ -50,6 +50,18 @@
         <a t:type="ActionLink" t:id="BadReturnValue">bad</a>
         return values.
     </p>
+    
+    <p>
+        Test
+        <a t:type="ActionLink" t:id="StreamPageContent">stream page content</a>
+        return values.
+    </p>
+    
+    <p>
+        Test
+        <a t:type="ActionLink" t:id="StreamPageContentWithContext">stream page 
content with context</a>
+        return values.
+    </p>
 
 
     <p>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=978870&r1=978869&r2=978870&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
 Sat Jul 24 13:30:16 2010
@@ -528,6 +528,17 @@ public class CoreBehaviorsTests extends 
         assertTextPresent("Success!");
         goBack();
         waitForPageToLoad();
+        
+        clickAndWait("link=stream page content");
+        assertTextPresent("Tapestry 5 Integration Application 1");
+        goBack();
+        waitForPageToLoad();
+
+        clickAndWait("link=stream page content with context");
+        assertTextPresent("music/Details", "Track Details");
+        assertTextPresent("Bug Juice", "Late Lounge", "Electronica");
+        goBack();
+        waitForPageToLoad();
 
         /*
          * clickAndWait("link=URL");

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java?rev=978870&r1=978869&r2=978870&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ReturnTypes.java
 Sat Jul 24 13:30:16 2010
@@ -16,9 +16,13 @@ package org.apache.tapestry5.integration
 
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.annotations.InjectPage;
+import org.apache.tapestry5.integration.app1.data.Track;
+import org.apache.tapestry5.integration.app1.pages.music.MusicDetails;
+import org.apache.tapestry5.integration.app1.services.MusicLibrary;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.services.ComponentEventResultProcessor;
 import org.apache.tapestry5.services.HttpError;
+import org.apache.tapestry5.services.StreamPageContent;
 import org.apache.tapestry5.util.TextStreamResponse;
 
 import java.net.MalformedURLException;
@@ -38,6 +42,9 @@ public class ReturnTypes
 
     @Inject
     private ComponentResources resources;
+    
+    @Inject
+    private MusicLibrary library;
 
     Object onActionFromNullReturnValue()
     {
@@ -81,7 +88,18 @@ public class ReturnTypes
         return new URL("http://google.com";);
     }
     
-
+    Object onActionFromStreamPageContent()
+    {   
+        return new StreamPageContent(Index.class);
+    }
+    
+    Object onActionFromStreamPageContentWithContext()
+    {
+        Track track = library.getById(294L);
+        
+        return new StreamPageContent(MusicDetails.class, track);
+    }
+    
 
     Object onActionFromHttpError()
     {


Reply via email to