1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.component; |
20 | |
|
21 | |
import java.util.Collection; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import javax.faces.component.visit.VisitCallback; |
25 | |
import javax.faces.component.visit.VisitContext; |
26 | |
import javax.faces.component.visit.VisitResult; |
27 | |
import javax.faces.context.ExternalContext; |
28 | |
import javax.faces.context.FacesContext; |
29 | |
|
30 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent; |
31 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty; |
32 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
@JSFComponent( |
42 | |
name="f:subview", |
43 | |
bodyContent="JSP", |
44 | |
tagClass="org.apache.myfaces.taglib.core.SubviewTag") |
45 | |
@JSFJspProperty(name="id",required=true) |
46 | |
public class UINamingContainer extends UIComponentBase implements NamingContainer, UniqueIdVendor |
47 | |
{ |
48 | |
public static final String COMPONENT_TYPE = "javax.faces.NamingContainer"; |
49 | |
public static final String COMPONENT_FAMILY = "javax.faces.NamingContainer"; |
50 | |
public static final String SEPARATOR_CHAR_PARAM_NAME = "javax.faces.SEPARATOR_CHAR"; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public UINamingContainer() |
56 | 30 | { |
57 | 30 | setRendererType(null); |
58 | 30 | } |
59 | |
|
60 | |
@Override |
61 | |
public String getFamily() |
62 | |
{ |
63 | 0 | return COMPONENT_FAMILY; |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public String createUniqueId(FacesContext context, String seed) |
73 | |
{ |
74 | 0 | StringBuilder bld = _getSharedStringBuilder(context); |
75 | |
|
76 | |
|
77 | |
|
78 | 0 | if(seed==null) |
79 | |
{ |
80 | 0 | Integer uniqueIdCounter = (Integer) getStateHelper().get(PropertyKeys.uniqueIdCounter); |
81 | 0 | uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter; |
82 | 0 | getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1)); |
83 | 0 | return bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(uniqueIdCounter).toString(); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
else |
88 | |
{ |
89 | 0 | return bld.append(UIViewRoot.UNIQUE_ID_PREFIX).append(seed).toString(); |
90 | |
} |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
@SuppressWarnings("deprecation") |
101 | |
public static char getSeparatorChar(FacesContext context) |
102 | |
{ |
103 | 42 | Map<Object, Object> attributes = context.getAttributes(); |
104 | 42 | Character separatorChar = (Character) attributes.get(SEPARATOR_CHAR_PARAM_NAME); |
105 | 42 | if (separatorChar == null) |
106 | |
{ |
107 | 42 | ExternalContext eContext = context.getExternalContext(); |
108 | |
|
109 | |
|
110 | |
|
111 | 42 | String param = eContext.getInitParameter(SEPARATOR_CHAR_PARAM_NAME); |
112 | 42 | if (param == null || param.length() == 0) |
113 | |
{ |
114 | |
|
115 | 42 | separatorChar = NamingContainer.SEPARATOR_CHAR; |
116 | |
} |
117 | |
else |
118 | |
{ |
119 | |
|
120 | |
|
121 | 0 | separatorChar = param.charAt(0); |
122 | |
} |
123 | |
|
124 | 42 | attributes.put(SEPARATOR_CHAR_PARAM_NAME, separatorChar); |
125 | |
} |
126 | 42 | return separatorChar.charValue(); |
127 | |
} |
128 | |
|
129 | |
@JSFProperty(deferredValueType="java.lang.Boolean") |
130 | |
@Override |
131 | |
public boolean isRendered() |
132 | |
{ |
133 | 0 | return super.isRendered(); |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public boolean visitTree(VisitContext context, VisitCallback callback) |
138 | |
{ |
139 | 0 | pushComponentToEL(context.getFacesContext(), this); |
140 | 0 | boolean isCachedFacesContext = isCachedFacesContext(); |
141 | |
try |
142 | |
{ |
143 | 0 | if (!isCachedFacesContext) |
144 | |
{ |
145 | 0 | setCachedFacesContext(context.getFacesContext()); |
146 | |
} |
147 | |
|
148 | 0 | if (!isVisitable(context)) |
149 | |
{ |
150 | 0 | return false; |
151 | |
} |
152 | |
|
153 | 0 | VisitResult res = context.invokeVisitCallback(this, callback); |
154 | 0 | switch (res) |
155 | |
{ |
156 | |
|
157 | |
case COMPLETE: |
158 | 0 | return true; |
159 | |
|
160 | |
case REJECT: |
161 | 0 | return false; |
162 | |
|
163 | |
|
164 | |
default: |
165 | |
|
166 | |
|
167 | 0 | Collection<String> subtreeIdsToVisit = context.getSubtreeIdsToVisit(this); |
168 | |
|
169 | 0 | if (subtreeIdsToVisit != null && !subtreeIdsToVisit.isEmpty()) |
170 | |
{ |
171 | 0 | if (getFacetCount() > 0) |
172 | |
{ |
173 | 0 | for (UIComponent facet : getFacets().values()) |
174 | |
{ |
175 | 0 | if (facet.visitTree(context, callback)) |
176 | |
{ |
177 | 0 | return true; |
178 | |
} |
179 | 0 | } |
180 | |
} |
181 | 0 | for (int i = 0, childCount = getChildCount(); i < childCount; i++) |
182 | |
{ |
183 | 0 | UIComponent child = getChildren().get(i); |
184 | 0 | if (child.visitTree(context, callback)) |
185 | |
{ |
186 | 0 | return true; |
187 | |
} |
188 | |
} |
189 | |
} |
190 | 0 | return false; |
191 | |
} |
192 | |
} |
193 | |
finally |
194 | |
{ |
195 | |
|
196 | 0 | popComponentFromEL(context.getFacesContext()); |
197 | 0 | if (!isCachedFacesContext) |
198 | |
{ |
199 | 0 | setCachedFacesContext(null); |
200 | |
} |
201 | |
} |
202 | |
} |
203 | |
|
204 | 0 | enum PropertyKeys |
205 | |
{ |
206 | 0 | uniqueIdCounter |
207 | |
} |
208 | |
} |