01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.integration.app1.pages;
16:
17: import java.util.Map;
18:
19: import org.apache.tapestry.Block;
20: import org.apache.tapestry.annotations.Inject;
21: import org.apache.tapestry.annotations.Persist;
22: import org.apache.tapestry.annotations.Retain;
23: import org.apache.tapestry.ioc.internal.util.CollectionFactory;
24:
25: public class BlockDemo {
26: @Inject
27: private Block _fred;
28:
29: @Inject
30: private Block _barney;
31:
32: // Blocks not injected until page load, so must lazily initialize the map.
33: @Retain
34: private Map<String, Block> _blocks = null;
35:
36: @Persist
37: private String _blockName;
38:
39: public Block getBlockToRender() {
40: if (_blocks == null) {
41: _blocks = CollectionFactory.newMap();
42: _blocks.put("fred", _fred);
43: _blocks.put("barney", _barney);
44: }
45:
46: return _blocks.get(_blockName);
47: }
48:
49: public String getBlockName() {
50: return _blockName;
51: }
52:
53: public void setBlockName(String blockName) {
54: _blockName = blockName;
55: }
56:
57: }
|