1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.tag.composite; |
20 | |
|
21 | |
import java.io.Serializable; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collections; |
24 | |
import java.util.List; |
25 | |
|
26 | |
import javax.el.ValueExpression; |
27 | |
import javax.faces.FacesException; |
28 | |
import javax.faces.component.UIComponent; |
29 | |
import javax.faces.component.behavior.ClientBehaviorHolder; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
|
32 | |
import org.apache.myfaces.shared.util.StringUtils; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class ClientBehaviorAttachedObjectTargetImpl |
39 | |
implements ClientBehaviorAttachedObjectTarget, Serializable |
40 | |
{ |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
private static final long serialVersionUID = -4645087262404844925L; |
46 | |
|
47 | |
protected ValueExpression _name; |
48 | |
|
49 | |
protected ValueExpression _targets; |
50 | |
|
51 | |
protected ValueExpression _event; |
52 | |
|
53 | |
protected boolean _default; |
54 | |
|
55 | |
public ClientBehaviorAttachedObjectTargetImpl() |
56 | 0 | { |
57 | 0 | } |
58 | |
|
59 | |
public String getName() |
60 | |
{ |
61 | 0 | if (_name != null) |
62 | |
{ |
63 | 0 | return (String) _name.getValue(FacesContext.getCurrentInstance().getELContext()); |
64 | |
} |
65 | 0 | return null; |
66 | |
} |
67 | |
|
68 | |
public List<UIComponent> getTargets(UIComponent topLevelComponent) |
69 | |
{ |
70 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
71 | 0 | String [] targetsArray = getTargets(facesContext); |
72 | |
|
73 | 0 | if (targetsArray.length > 0) |
74 | |
{ |
75 | 0 | List<UIComponent> targetsList = new ArrayList<UIComponent>(targetsArray.length); |
76 | 0 | for (String target : targetsArray) |
77 | |
{ |
78 | 0 | UIComponent innerComponent = topLevelComponent.findComponent(target); |
79 | |
|
80 | 0 | if (innerComponent != null) |
81 | |
{ |
82 | 0 | if (innerComponent instanceof ClientBehaviorHolder || |
83 | |
UIComponent.isCompositeComponent(innerComponent)) |
84 | |
{ |
85 | 0 | targetsList.add( |
86 | |
new ClientBehaviorRedirectEventComponentWrapper(innerComponent, getName(), getEvent())); |
87 | |
} |
88 | |
else |
89 | |
{ |
90 | 0 | throw new FacesException("Component with clientId " + innerComponent.getClientId(facesContext) |
91 | |
+ "should be instance of ClientBehaviorHolder"); |
92 | |
} |
93 | |
} |
94 | |
} |
95 | 0 | return targetsList; |
96 | |
} |
97 | |
else |
98 | |
{ |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 0 | String name = getName(); |
104 | 0 | if (name != null) |
105 | |
{ |
106 | 0 | UIComponent innerComponent = topLevelComponent.findComponent(getName()); |
107 | 0 | if (innerComponent != null) |
108 | |
{ |
109 | 0 | if (innerComponent instanceof ClientBehaviorHolder || |
110 | |
UIComponent.isCompositeComponent(innerComponent)) |
111 | |
{ |
112 | 0 | List<UIComponent> targetsList = new ArrayList<UIComponent>(1); |
113 | 0 | targetsList.add( |
114 | |
new ClientBehaviorRedirectEventComponentWrapper(innerComponent, getName(), getEvent())); |
115 | 0 | return targetsList; |
116 | |
} |
117 | |
else |
118 | |
{ |
119 | 0 | throw new FacesException("Component with clientId "+ innerComponent.getClientId(facesContext) |
120 | |
+ "should be instance of ClientBehaviorHolder"); |
121 | |
} |
122 | |
} |
123 | |
} |
124 | 0 | return Collections.emptyList(); |
125 | |
} |
126 | |
} |
127 | |
|
128 | |
public String [] getTargets(FacesContext context) |
129 | |
{ |
130 | 0 | if (_targets != null) |
131 | |
{ |
132 | 0 | return StringUtils.splitShortString((String) _targets.getValue(context.getELContext()), ' '); |
133 | |
} |
134 | 0 | return org.apache.myfaces.shared.util.ArrayUtils.EMPTY_STRING_ARRAY; |
135 | |
} |
136 | |
|
137 | |
public void setName(ValueExpression name) |
138 | |
{ |
139 | 0 | _name = name; |
140 | 0 | } |
141 | |
|
142 | |
public void setTargets(ValueExpression ve) |
143 | |
{ |
144 | 0 | _targets = ve; |
145 | 0 | } |
146 | |
|
147 | |
public String getEvent() |
148 | |
{ |
149 | 0 | if (_event != null) |
150 | |
{ |
151 | 0 | return (String) _event.getValue(FacesContext.getCurrentInstance().getELContext()); |
152 | |
} |
153 | 0 | return null; |
154 | |
} |
155 | |
|
156 | |
public void setEvent(ValueExpression event) |
157 | |
{ |
158 | 0 | this._event = event; |
159 | 0 | } |
160 | |
|
161 | |
public boolean isDefaultEvent() |
162 | |
{ |
163 | 0 | return _default; |
164 | |
} |
165 | |
|
166 | |
public void setDefault(boolean default1) |
167 | |
{ |
168 | 0 | _default = default1; |
169 | 0 | } |
170 | |
} |