1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.component.behavior; |
20 | |
|
21 | |
import java.util.Collections; |
22 | |
import java.util.Set; |
23 | |
|
24 | |
import javax.faces.component.UIComponent; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.faces.render.ClientBehaviorRenderer; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class ClientBehaviorBase extends BehaviorBase implements ClientBehavior |
32 | |
{ |
33 | |
|
34 | |
private transient FacesContext _facesContext; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public ClientBehaviorBase() |
40 | 0 | { |
41 | 0 | } |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public void decode(FacesContext context, UIComponent component) |
47 | |
{ |
48 | 0 | if (context == null) |
49 | |
{ |
50 | 0 | throw new NullPointerException("context"); |
51 | |
} |
52 | |
|
53 | 0 | if (component == null) |
54 | |
{ |
55 | 0 | throw new NullPointerException("component"); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | 0 | ClientBehaviorRenderer renderer = getRenderer(context); |
61 | 0 | if (renderer != null) |
62 | |
{ |
63 | 0 | renderer.decode(context, component, this); |
64 | |
} |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public Set<ClientBehaviorHint> getHints() |
71 | |
{ |
72 | 0 | return Collections.<ClientBehaviorHint>emptySet(); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public String getRendererType() |
79 | |
{ |
80 | 0 | return null; |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public String getScript(ClientBehaviorContext behaviorContext) |
87 | |
{ |
88 | 0 | if (behaviorContext == null) |
89 | |
{ |
90 | 0 | throw new NullPointerException("behaviorContext"); |
91 | |
} |
92 | |
|
93 | 0 | ClientBehaviorRenderer renderer = getRenderer(behaviorContext.getFacesContext()); |
94 | 0 | if (renderer != null) |
95 | |
{ |
96 | |
|
97 | |
|
98 | |
try |
99 | |
{ |
100 | 0 | setCachedFacesContext(behaviorContext.getFacesContext()); |
101 | 0 | return renderer.getScript(behaviorContext, this); |
102 | |
} |
103 | |
finally |
104 | |
{ |
105 | 0 | setCachedFacesContext(null); |
106 | |
} |
107 | |
} |
108 | |
|
109 | |
|
110 | 0 | return null; |
111 | |
} |
112 | |
|
113 | |
protected ClientBehaviorRenderer getRenderer(FacesContext context) |
114 | |
{ |
115 | 0 | if (context == null) |
116 | |
{ |
117 | 0 | throw new NullPointerException("context"); |
118 | |
} |
119 | |
|
120 | 0 | String rendererType = getRendererType(); |
121 | 0 | if (rendererType != null) |
122 | |
{ |
123 | 0 | return context.getRenderKit().getClientBehaviorRenderer(rendererType); |
124 | |
} |
125 | |
|
126 | 0 | return null; |
127 | |
} |
128 | |
|
129 | |
FacesContext getFacesContext() |
130 | |
{ |
131 | 0 | if (_facesContext == null) |
132 | |
{ |
133 | 0 | return FacesContext.getCurrentInstance(); |
134 | |
} |
135 | |
else |
136 | |
{ |
137 | 0 | return _facesContext; |
138 | |
} |
139 | |
} |
140 | |
|
141 | |
boolean isCachedFacesContext() |
142 | |
{ |
143 | 0 | return _facesContext != null; |
144 | |
} |
145 | |
|
146 | |
void setCachedFacesContext(FacesContext facesContext) |
147 | |
{ |
148 | 0 | _facesContext = facesContext; |
149 | 0 | } |
150 | |
} |