Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ComponentHandler |
|
| 2.2857142857142856;2.286 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package javax.faces.view.facelets; | |
20 | ||
21 | import javax.faces.component.UIComponent; | |
22 | ||
23 | /** | |
24 | * Implementation of the tag logic used in the JSF specification. This is your golden hammer for wiring UIComponents to | |
25 | * Facelets. | |
26 | */ | |
27 | public class ComponentHandler extends DelegatingMetaTagHandler | |
28 | { | |
29 | private ComponentConfig config; | |
30 | private TagHandlerDelegate helper; | |
31 | ||
32 | public ComponentHandler(ComponentConfig config) | |
33 | { | |
34 | 0 | super(config); |
35 | ||
36 | 0 | this.config = config; |
37 | ||
38 | 0 | } |
39 | ||
40 | public ComponentConfig getComponentConfig() | |
41 | { | |
42 | 0 | return config; |
43 | } | |
44 | ||
45 | public static boolean isNew(UIComponent component) | |
46 | { | |
47 | // -= Leonardo Uribe =- It seems org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport.isNew(UIComponent) | |
48 | // has been moved to this location. | |
49 | // Originally this method was called from all tags that generate any kind of listeners | |
50 | // (f:actionListener, f:phaseListener, f:setPropertyActionListener, f:valueChangeListener). | |
51 | // This method prevent add listener when a facelet is applied twice. | |
52 | // On MYFACES-2502 there is an explanation about where this is useful (partial state saving disabled). | |
53 | // return component != null && component.getParent() == null; | |
54 | 0 | if (component != null) |
55 | { | |
56 | 0 | UIComponent parent = component.getParent(); |
57 | 0 | if (parent == null) |
58 | { | |
59 | 0 | return true; |
60 | } | |
61 | else | |
62 | { | |
63 | // When a composite component is used, we could have tags attaching | |
64 | // objects or doing some operation on composite:implementation body | |
65 | // like this: | |
66 | // <composite:implementation> | |
67 | // <f:event ...../> | |
68 | // </composite:implementation> | |
69 | // This case is valid, but the parent is the UIPanel inside | |
70 | // UIComponent.COMPOSITE_FACET_NAME facet key of the composite component. | |
71 | // So in this case we have to check if the component is a composite component | |
72 | // or not and if so, try to get the parent again. | |
73 | 0 | if (UIComponent.isCompositeComponent(parent)) |
74 | { | |
75 | 0 | parent = parent.getParent(); |
76 | 0 | if (parent == null) |
77 | { | |
78 | 0 | return true; |
79 | } | |
80 | else | |
81 | { | |
82 | 0 | return false; |
83 | } | |
84 | } | |
85 | else | |
86 | { | |
87 | 0 | return false; |
88 | } | |
89 | } | |
90 | } | |
91 | else | |
92 | { | |
93 | 0 | return false; |
94 | } | |
95 | } | |
96 | ||
97 | public void onComponentCreated(FaceletContext ctx, UIComponent c, UIComponent parent) | |
98 | { | |
99 | // no-op. | |
100 | 0 | } |
101 | ||
102 | public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent) | |
103 | { | |
104 | // no-op. | |
105 | 0 | } |
106 | ||
107 | protected TagHandlerDelegate getTagHandlerDelegate() | |
108 | { | |
109 | 0 | if (helper == null) |
110 | { | |
111 | // Spec seems to indicate that the helper is created here, as opposed to other Handler | |
112 | // instances, where it's presumably a new instance for every getter call. | |
113 | ||
114 | 0 | this.helper = delegateFactory.createComponentHandlerDelegate (this); |
115 | } | |
116 | 0 | return helper; |
117 | } | |
118 | ||
119 | /** | |
120 | * | |
121 | * @since 2.2 | |
122 | * @param ctx | |
123 | * @return | |
124 | */ | |
125 | public UIComponent createComponent(FaceletContext ctx) | |
126 | { | |
127 | 0 | return null; |
128 | } | |
129 | } |