01: /* CustomeAttributes.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: 2007/08/16 18:10:17 , 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.Iterator;
24: import java.util.Map;
25:
26: import javax.faces.context.FacesContext;
27:
28: import org.zkoss.zk.ui.Component;
29:
30: /**
31: * A Implement of customer-attributes tag<br/>
32: * @author Dennis.Chen
33: *
34: */
35: public class BaseCustomAttributes extends AbstractComponent {
36: private Map _compAttrMap;
37:
38: public void encodeBegin(FacesContext context) throws IOException {
39: if (!isRendered() || !isEffective())
40: return; //nothing to do
41: super .encodeBegin(context);
42: final AbstractComponent ac = (AbstractComponent) findAncestorWithClass(
43: this , AbstractComponent.class);
44: if (ac instanceof BranchComponent) {
45: ((BranchComponent) ac).setZULCustomAttribute(_compAttrMap);
46: } else {
47: throw new IllegalStateException(
48: "Must be nested inside the BranchComponent: "
49: + this );
50: }
51: }
52:
53: /**
54: * Set dynamic attribute of Initiator
55: *
56: * @param map
57: * the dynamic attributes.
58: */
59: public void setDynamicAttribute(Map map) {
60: _compAttrMap = map;
61: }
62:
63: // ----------------------------------------------------- StateHolder Methods
64:
65: /**
66: * Override Method, save the state of this component.
67: */
68: public Object saveState(FacesContext context) {
69: Object values[] = new Object[3];
70: values[0] = super .saveState(context);
71: Object m[] = saveAttachedMapState(context, _compAttrMap);
72: values[1] = m[0];
73: values[2] = m[1];
74: return (values);
75:
76: }
77:
78: /**
79: * Override Method, restore the state of this component.
80: */
81: public void restoreState(FacesContext context, Object state) {
82: Object values[] = (Object[]) state;
83: super .restoreState(context, values[0]);
84: _compAttrMap = (Map) restoreAttachedMapState(context,
85: values[1], values[2]);
86: }
87: }
|