001// Copyright 2008, 2010 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.internal.services; 016 017import java.io.IOException; 018 019import org.apache.tapestry5.internal.InternalConstants; 020import org.apache.tapestry5.internal.structure.Page; 021import org.apache.tapestry5.services.Request; 022 023/** 024 * Alternative implementation, used when {@link org.apache.tapestry5.SymbolConstants#SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS} 025 * is set to true. 026 */ 027public class ImmediateActionRenderResponseGenerator implements ActionRenderResponseGenerator 028{ 029 private final Request request; 030 031 public ImmediateActionRenderResponseGenerator(Request request) 032 { 033 this.request = request; 034 } 035 036 public void generateResponse(Page page) throws IOException 037 { 038 assert page != null; 039 if (request.getAttribute(InternalConstants.IMMEDIATE_RESPONSE_PAGE_ATTRIBUTE) != null) return; 040 041 // We are somewhere in the middle of processing an action request, possibly something 042 // complicated like a form submission. Tapestry components are not re-entrant, so we 043 // can't render the request right now, instead we record that we need to render 044 // a response as an attribute, and let a filter on the ComponentEventRequestHandler service 045 // do the work. 046 047 request.setAttribute(InternalConstants.IMMEDIATE_RESPONSE_PAGE_ATTRIBUTE, page); 048 } 049}