001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.corelib.components; 014 015import org.apache.tapestry5.Block; 016import org.apache.tapestry5.ComponentResources; 017import org.apache.tapestry5.annotations.InjectContainer; 018import org.apache.tapestry5.annotations.Parameter; 019import org.apache.tapestry5.annotations.SupportsInformalParameters; 020import org.apache.tapestry5.ioc.annotations.Inject; 021import org.apache.tapestry5.runtime.Component; 022 023/** 024 * A component that does not do any rendering of its own, but will delegate to some other object that can do rendering. 025 * This other object may be a component or a {@link Block} (among other things). 026 * 027 * This component may also be used to create inline components. For each informal parameter the value will be stored as a 028 * render variable. To create an inline component, create a block 029 * and use Delegate multiple times in the template to render the block passing parameters to Delegate. In the block body 030 * reference the render variables using the "var:" binding prefix and the name of the parameter. 031 * 032 * Note that the default binding prefix for informal parameter values is "literal". 033 * 034 * @tapestrydoc 035 */ 036@SupportsInformalParameters 037public class Delegate 038{ 039 /** 040 * The object which will be rendered in place of the Delegate component. This is typically a specific component 041 * instance, or a {@link Block}. 042 */ 043 @Parameter(required = true) 044 private Object to; 045 046 @Inject private ComponentResources resources; 047 @InjectContainer private Component container; 048 049 Object beginRender() 050 { 051 for(String name : resources.getInformalParameterNames()) { 052 Object value = resources.getInformalParameter(name, Object.class); 053 container.getComponentResources().storeRenderVariable(name, value); 054 } 055 056 return to; 057 } 058}