|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
BlockRenderer.java | - | 0% | 0% | 0% |
|
1 | // Copyright 2004, 2005 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.tapestry.components; | |
16 | ||
17 | import org.apache.tapestry.IMarkupWriter; | |
18 | import org.apache.tapestry.IRender; | |
19 | import org.apache.tapestry.IRequestCycle; | |
20 | ||
21 | /** | |
22 | * An implementation of IRender that renders a Block component. | |
23 | * | |
24 | * <p>The BlockRenderer allows the contents of a {@link Block} to be rendered | |
25 | * via {@link IRender}. It can be used in cases when an {@link IRender} object is | |
26 | * required as an argument or a binding to render a part of a Component. | |
27 | * To provide a complicated view, it could be defined in a {@link Block} and then | |
28 | * returned encapsulated in a BlockRenderer. | |
29 | * | |
30 | * <p>It is important to note that a special care has to be taken if | |
31 | * the BlockRenderer is used within an inner class of a component or a page. | |
32 | * In such a case the instance of the component that created the inner class | |
33 | * may not be the currently active instance in the RequestCycle when the | |
34 | * BlockRenderer is required. Thus, calling getComponent("blockName") to get the | |
35 | * block component may return a Block component that is not initialized for this | |
36 | * RequestCycle. | |
37 | * | |
38 | * <p>To avoid similar problems, the ComponentAddress class could be used in | |
39 | * conjunction with BlockRenderer. | |
40 | * Here is a quick example of how BlockRenderer could be used with ComponentAddress: | |
41 | * <p> | |
42 | * <code> | |
43 | * <br>// Create a component address for the current component | |
44 | * <br>final ComponentAddress address = new ComponentAddress(this); | |
45 | * <br>return new SomeClass() { | |
46 | * <br> IRender getRenderer(IRequestCycle cycle) { | |
47 | * <br> MyComponent component = (MyComponent) address.findComponent(cycle); | |
48 | * <br> // initialize variables in the component that will be used by the block here | |
49 | * <br> return new BlockRenderer(component.getComponent("block")); | |
50 | * <br> } | |
51 | * <br>} | |
52 | * </code> | |
53 | * | |
54 | * @author mindbridge | |
55 | * @since 2.2 | |
56 | */ | |
57 | public class BlockRenderer implements IRender | |
58 | { | |
59 | private Block m_objBlock; | |
60 | ||
61 | /** | |
62 | * Creates a new BlockRenderer that will render the content of the argument | |
63 | * @param objBlock the Block to be rendered | |
64 | */ | |
65 | 0 | public BlockRenderer(Block objBlock) |
66 | { | |
67 | 0 | m_objBlock = objBlock; |
68 | } | |
69 | ||
70 | /** | |
71 | * @see org.apache.tapestry.IRender#render(IMarkupWriter, IRequestCycle) | |
72 | */ | |
73 | 0 | public void render(IMarkupWriter writer, IRequestCycle cycle) |
74 | { | |
75 | 0 | m_objBlock.renderBody(writer, cycle); |
76 | } | |
77 | ||
78 | } |
|