1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.navigation;
20
21 import java.io.IOException;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import javax.faces.component.UIComponent;
26 import javax.faces.component.UIViewRoot;
27 import javax.faces.context.FacesContext;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.myfaces.component.AlignProperty;
32 import org.apache.myfaces.component.DataProperties;
33 import org.apache.myfaces.component.EventAware;
34 import org.apache.myfaces.component.PanelProperties;
35 import org.apache.myfaces.component.UniversalProperties;
36 import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public abstract class AbstractHtmlPanelNavigation
56 extends HtmlPanelGroup implements AlignProperty,
57 UniversalProperties, EventAware, DataProperties, PanelProperties
58 {
59 private static final Log log = LogFactory.getLog(AbstractHtmlPanelNavigation.class);
60
61 public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlPanelNavigation";
62 public static final String COMPONENT_FAMILY = "javax.faces.Panel";
63 private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Navigation";
64
65 private static final int DEFAULT_BORDER = Integer.MIN_VALUE;
66
67 private static final String PREVIOUS_VIEW_ROOT = AbstractHtmlPanelNavigation.class.getName() + ".PREVIOUS_VIEW_ROOT";
68 private boolean _itemOpenActiveStatesRestored = false;
69
70 public void decode(FacesContext context)
71 {
72 super.decode(context);
73
74
75 context.getExternalContext().getRequestMap().put(PREVIOUS_VIEW_ROOT, context.getViewRoot());
76
77 _itemOpenActiveStatesRestored = true;
78 }
79
80 public void encodeBegin(FacesContext context) throws IOException
81 {
82 if (!_itemOpenActiveStatesRestored && getChildCount() > 0)
83 {
84 UIViewRoot previousRoot = (UIViewRoot)context.getExternalContext().getRequestMap().get(PREVIOUS_VIEW_ROOT);
85 if (previousRoot != null)
86 {
87 restoreOpenActiveStates(context, previousRoot, getChildren());
88 }
89 else
90 {
91
92
93 }
94 }
95
96 super.encodeBegin(context);
97 }
98
99 public void restoreOpenActiveStates(FacesContext facesContext,
100 UIViewRoot previousRoot,
101 List children)
102 {
103 for (Iterator it = children.iterator(); it.hasNext(); )
104 {
105 UIComponent child = (UIComponent)it.next();
106 if (child instanceof HtmlCommandNavigation)
107 {
108 HtmlCommandNavigation previousItem = (HtmlCommandNavigation)previousRoot.findComponent(child.getClientId(facesContext));
109 if (previousItem != null)
110 {
111
112 HtmlCommandNavigation childItem = (HtmlCommandNavigation)child;
113 if(previousItem.getOpenDirectly()!=null)
114 {
115 childItem.setOpen(previousItem.isOpen());
116 }
117 else if(previousItem.getValueBinding("open")!=null)
118 {
119 childItem.setValueBinding("open",previousItem.getValueBinding("open"));
120 }
121
122 if(previousItem.getActiveDirectly()!=null)
123 {
124 childItem.setActive(previousItem.isActive());
125 }
126 else if(previousItem.getValueBinding("active")!=null)
127 {
128 childItem.setValueBinding("active",previousItem.getValueBinding("active"));
129 }
130 }
131 else
132 {
133 log.error("Navigation item " + child.getClientId(facesContext) + " not found in previous view.");
134 }
135 if (child.getChildCount() > 0)
136 {
137 restoreOpenActiveStates(facesContext, previousRoot, child.getChildren());
138 }
139 }
140 }
141 }
142
143
144
145
146
147
148 public abstract String getItemClass();
149
150
151
152
153
154
155 public abstract String getOpenItemClass();
156
157
158
159
160
161
162 public abstract String getActiveItemClass();
163
164
165
166
167
168
169 public abstract String getSeparatorClass();
170
171
172
173
174
175
176 public abstract String getItemStyle();
177
178
179
180
181
182
183 public abstract String getOpenItemStyle();
184
185
186
187
188
189
190 public abstract String getActiveItemStyle();
191
192
193
194
195
196
197 public abstract String getSeparatorStyle();
198
199 }