001 // Copyright 2004, 2005 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 015 package org.apache.tapestry.components; 016 017 import org.apache.tapestry.AbstractComponent; 018 import org.apache.tapestry.IMarkupWriter; 019 import org.apache.tapestry.IRequestCycle; 020 021 /** 022 * Renders the text and components wrapped by a {@link Block}component. [ <a 023 * href="../../../../../ComponentReference/RenderBlock.html">Component Reference 024 * </a>] 025 * <p> 026 * It is possible for an RenderBlock to obtain a Block from a page 027 * <em>other than</em> the render page. This works, even when the Block 028 * contains links, forms and form components. The action and direct services 029 * will create URLs that properly address this situation. 030 * <p> 031 * However, because the rendering page can't know ahead of time about these 032 * foreign Blocks, {@link org.apache.tapestry.event.PageBeginRenderListener} and 033 * {@link org.apache.tapestry.event.PageEndRenderListener} methods (for 034 * components and objects of the foreign page) via RenderBlock will <em>not</em> 035 * be executed. This specifically affects the methods of the 036 * {@link org.apache.tapestry.event.PageBeginRenderListener} and 037 * {@link org.apache.tapestry.event.PageEndRenderListener} interfaces. 038 * <p> 039 * Before rendering its {@link Block}, RenderBlock will set itself as the 040 * Block's inserter, and will reset the inserter after the {@link Block}is 041 * rendered. This gives the components contained in the {@link Block}access to 042 * its inserted environment via the RenderBlock. In particular this allows the 043 * contained components to access the informal parameters of the RenderBlock 044 * which effectively allows parameters to be passed to the components contained 045 * in a Block. 046 * 047 * @author Howard Lewis Ship 048 */ 049 050 public abstract class RenderBlock extends AbstractComponent 051 { 052 053 /** 054 * If block is not null, then 055 * {@link Block#renderForComponent(IMarkupWriter, IRequestCycle, IComponent)} 056 * is invoked. 057 */ 058 059 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 060 { 061 Block block = getBlock(); 062 063 if (block == null) return; 064 065 block.renderForComponent(writer, cycle, this); 066 } 067 068 public abstract Block getBlock(); 069 070 }