Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
RenderBlock |
|
| 2.0;2 |
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.AbstractComponent; |
|
18 | import org.apache.tapestry.IMarkupWriter; |
|
19 | import org.apache.tapestry.IRequestCycle; |
|
20 | ||
21 | /** |
|
22 | * Renders the text and components wrapped by a {@link Block}component. [ <a |
|
23 | * href="../../../../../ComponentReference/RenderBlock.html">Component Reference |
|
24 | * </a>] |
|
25 | * <p> |
|
26 | * It is possible for an RenderBlock to obtain a Block from a page |
|
27 | * <em>other than</em> the render page. This works, even when the Block |
|
28 | * contains links, forms and form components. The action and direct services |
|
29 | * will create URLs that properly address this situation. |
|
30 | * <p> |
|
31 | * However, because the rendering page can't know ahead of time about these |
|
32 | * foreign Blocks, {@link org.apache.tapestry.event.PageBeginRenderListener} and |
|
33 | * {@link org.apache.tapestry.event.PageEndRenderListener} methods (for |
|
34 | * components and objects of the foreign page) via RenderBlock will <em>not</em> |
|
35 | * be executed. This specifically affects the methods of the |
|
36 | * {@link org.apache.tapestry.event.PageBeginRenderListener} and |
|
37 | * {@link org.apache.tapestry.event.PageEndRenderListener} interfaces. |
|
38 | * <p> |
|
39 | * Before rendering its {@link Block}, RenderBlock will set itself as the |
|
40 | * Block's inserter, and will reset the inserter after the {@link Block}is |
|
41 | * rendered. This gives the components contained in the {@link Block}access to |
|
42 | * its inserted environment via the RenderBlock. In particular this allows the |
|
43 | * contained components to access the informal parameters of the RenderBlock |
|
44 | * which effectively allows parameters to be passed to the components contained |
|
45 | * in a Block. |
|
46 | * |
|
47 | * @author Howard Lewis Ship |
|
48 | */ |
|
49 | ||
50 | 2 | public abstract class RenderBlock extends AbstractComponent |
51 | { |
|
52 | ||
53 | /** |
|
54 | * If block is not null, then |
|
55 | * {@link Block#renderForComponent(IMarkupWriter, IRequestCycle, IComponent)} |
|
56 | * is invoked. |
|
57 | */ |
|
58 | ||
59 | protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
60 | { |
|
61 | 2 | Block block = getBlock(); |
62 | ||
63 | 2 | if (block == null) return; |
64 | ||
65 | 1 | block.renderForComponent(writer, cycle, this); |
66 | 1 | } |
67 | ||
68 | public abstract Block getBlock(); |
|
69 | ||
70 | } |