01: /* BranchComponent.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Aug 7, 2007 5:56:04 PM 2007, Created by Dennis.Chen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.jsf.zul.impl;
20:
21: import java.io.IOException;
22: import java.io.StringWriter;
23: import java.util.ArrayList;
24: import java.util.Iterator;
25: import java.util.List;
26:
27: import org.zkoss.zk.ui.Component;
28:
29: /**
30: * The skeletal class used to implement the ZULJSF components
31: * that might have child ZULJSF components.
32: * This component should be declared nested under {@link org.zkoss.jsf.zul.Page}.
33: * @author Dennis.Chen
34: */
35: abstract public class BranchComponent extends LeafComponent {
36:
37: /** Adds a child ZUL Component.
38: */
39: /*package*/void addChildZULComponent(LeafComponent child) {
40: if (child instanceof BaseUi) {
41: Component[] comps = ((BaseUi) child).getComponent();
42: for (int i = 0; i < comps.length; i++) {
43: comps[i].setParent(getZULComponent());
44: }
45: } else {
46: child.getZULComponent().setParent(getZULComponent());
47: }
48: }
49:
50: /**
51: * Call by RootComponent or BranchComponent to load zk stuff and all it's children
52: */
53: protected void loadZULTree(org.zkoss.zk.ui.Page page,
54: StringWriter writer) throws IOException {
55: if (!isRendered() || !isEffective())
56: return; //nothing to do
57: _composer = new ComposerHandler(getAttributeValue("apply"));
58: initComponent(page);
59:
60: //load children
61: ComponentInfo ci = getComponentInfo();
62: List children = ci.getChildrenInfo(this );
63: if (children != null) {
64: for (Iterator kids = children.iterator(); kids.hasNext();) {
65: AbstractComponent kid = (AbstractComponent) kids.next();
66: kid.loadZULTree(page, writer);
67: }
68: String bodyContent = getBodyContent();
69: Utils.adjustChildren(null, this , ci.getChildrenInfo(this ),
70: bodyContent);
71: } else {
72: //bug #1832862 Content disappear in JSFComponent
73: Utils.adjustChildren(null, this , new ArrayList(),
74: getBodyContent());
75: }
76: afterComposeComponent();// after Compose Component.
77: _composer = null;
78: setBodyContent(null); //clear
79:
80: }
81:
82: }
|