001 // Copyright 2007, 2008, 2011 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.tapestry5.corelib.components; 016 017 import org.apache.tapestry5.Block; 018 import org.apache.tapestry5.ComponentResources; 019 import org.apache.tapestry5.annotations.InjectContainer; 020 import org.apache.tapestry5.annotations.Parameter; 021 import org.apache.tapestry5.annotations.SupportsInformalParameters; 022 import org.apache.tapestry5.ioc.annotations.Inject; 023 import org.apache.tapestry5.runtime.Component; 024 025 /** 026 * A component that does not do any rendering of its own, but will delegate to some other object that can do rendering. 027 * This other object may be a component or a {@link Block} (among other things). 028 * <p> 029 * This component may also be used to create inline components. For each informal parameter the value will be stored as a 030 * render variable. To create an inline component, create a block 031 * and use Delegate multiple times in the template to render the block passing parameters to Delegate. In the block body 032 * reference the render variables using the "var:" binding prefix and the name of the parameter. 033 * <p> 034 * Note that the default binding prefix for informal parameter values is "literal". 035 * 036 * @tapestrydoc 037 */ 038 @SupportsInformalParameters 039 public class Delegate 040 { 041 /** 042 * The object which will be rendered in place of the Delegate component. This is typically a specific component 043 * instance, or a {@link Block}. 044 */ 045 @Parameter(required = true) 046 private Object to; 047 048 @Inject private ComponentResources resources; 049 @InjectContainer private Component container; 050 051 Object beginRender() 052 { 053 for(String name : resources.getInformalParameterNames()) { 054 Object value = resources.getInformalParameter(name, Object.class); 055 container.getComponentResources().storeRenderVariable(name, value); 056 } 057 058 return to; 059 } 060 }