Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.internal.services » [javadoc | source]
    1   // Copyright 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // Unless required by applicable law or agreed to in writing, software
   10   // distributed under the License is distributed on an "AS IS" BASIS,
   11   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12   // See the License for the specific language governing permissions and
   13   // limitations under the License.
   14   
   15   package org.apache.tapestry5.internal.services;
   16   
   17   import org.apache.tapestry5.EventConstants;
   18   import org.apache.tapestry5.internal.InternalConstants;
   19   import org.apache.tapestry5.internal.structure.Page;
   20   import org.apache.tapestry5.services;
   21   
   22   import java.io.IOException;
   23   
   24   public class ImmediateActionRenderResponseFilter implements ComponentEventRequestFilter
   25   {
   26       private final Request request;
   27   
   28       private final Response response;
   29   
   30       private final PageResponseRenderer renderer;
   31   
   32       public ImmediateActionRenderResponseFilter(Request request, PageResponseRenderer renderer, Response response)
   33       {
   34           this.request = request;
   35           this.renderer = renderer;
   36           this.response = response;
   37       }
   38   
   39       public void handle(ComponentEventRequestParameters parameters, ComponentEventRequestHandler handler)
   40               throws IOException
   41       {
   42           handler.handle(parameters);
   43   
   44           // If markup or a redirect has already been generated, then we're good.
   45   
   46           if (response.isCommitted()) return;
   47   
   48           // Otherwise, we should be operating in immediate mode.  Figure out which page
   49           // was selected to render.
   50   
   51           Page page = (Page) request.getAttribute(InternalConstants.IMMEDIATE_RESPONSE_PAGE_ATTRIBUTE);
   52   
   53           if (page != null)
   54           {
   55               // We don't have a context to provide but this still nags me as not the right thing to do.
   56   
   57               page.getRootElement().triggerEvent(EventConstants.ACTIVATE, new Object[0], null);
   58   
   59               renderer.renderPageResponse(page);
   60               return;
   61           }
   62   
   63           throw new IllegalStateException(
   64                   "Sanity check - neither a stream response nor a redirect response was generated for this action request.");
   65       }
   66   }

Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.internal.services » [javadoc | source]