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 {
57 }
58
59 public String getName()
60 {
61 if (_name != null)
62 {
63 return (String) _name.getValue(FacesContext.getCurrentInstance().getELContext());
64 }
65 return null;
66 }
67
68 public List<UIComponent> getTargets(UIComponent topLevelComponent)
69 {
70 FacesContext facesContext = FacesContext.getCurrentInstance();
71 String [] targetsArray = getTargets(facesContext);
72
73 if (targetsArray.length > 0)
74 {
75 List<UIComponent> targetsList = new ArrayList<UIComponent>(targetsArray.length);
76 for (String target : targetsArray)
77 {
78 UIComponent innerComponent = topLevelComponent.findComponent(target);
79
80 if (innerComponent != null)
81 {
82 if (innerComponent instanceof ClientBehaviorHolder ||
83 UIComponent.isCompositeComponent(innerComponent))
84 {
85 targetsList.add(
86 new ClientBehaviorRedirectEventComponentWrapper(innerComponent, getName(), getEvent()));
87 }
88 else
89 {
90 throw new FacesException("Component with clientId " + innerComponent.getClientId(facesContext)
91 + "should be instance of ClientBehaviorHolder");
92 }
93 }
94 }
95 return targetsList;
96 }
97 else
98 {
99
100
101
102
103 String name = getName();
104 if (name != null)
105 {
106 UIComponent innerComponent = topLevelComponent.findComponent(getName());
107 if (innerComponent != null)
108 {
109 if (innerComponent instanceof ClientBehaviorHolder ||
110 UIComponent.isCompositeComponent(innerComponent))
111 {
112 List<UIComponent> targetsList = new ArrayList<UIComponent>(1);
113 targetsList.add(
114 new ClientBehaviorRedirectEventComponentWrapper(innerComponent, getName(), getEvent()));
115 return targetsList;
116 }
117 else
118 {
119 throw new FacesException("Component with clientId "+ innerComponent.getClientId(facesContext)
120 + "should be instance of ClientBehaviorHolder");
121 }
122 }
123 }
124 return Collections.emptyList();
125 }
126 }
127
128 public String [] getTargets(FacesContext context)
129 {
130 if (_targets != null)
131 {
132 return StringUtils.splitShortString((String) _targets.getValue(context.getELContext()), ' ');
133 }
134 return org.apache.myfaces.shared.util.ArrayUtils.EMPTY_STRING_ARRAY;
135 }
136
137 public void setName(ValueExpression name)
138 {
139 _name = name;
140 }
141
142 public void setTargets(ValueExpression ve)
143 {
144 _targets = ve;
145 }
146
147 public String getEvent()
148 {
149 if (_event != null)
150 {
151 return (String) _event.getValue(FacesContext.getCurrentInstance().getELContext());
152 }
153 return null;
154 }
155
156 public void setEvent(ValueExpression event)
157 {
158 this._event = event;
159 }
160
161 public boolean isDefaultEvent()
162 {
163 return _default;
164 }
165
166 public void setDefault(boolean default1)
167 {
168 _default = default1;
169 }
170 }