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.component.UIComponent; |
28 | |
import javax.faces.context.FacesContext; |
29 | |
import javax.faces.view.AttachedObjectTarget; |
30 | |
|
31 | |
import org.apache.myfaces.shared.util.StringUtils; |
32 | |
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class AttachedObjectTargetImpl implements AttachedObjectTarget, Serializable |
40 | |
{ |
41 | |
|
42 | |
|
43 | |
|
44 | |
private static final long serialVersionUID = -7214478234269252354L; |
45 | |
|
46 | |
protected ValueExpression _name; |
47 | |
|
48 | |
protected ValueExpression _targets; |
49 | |
|
50 | |
public AttachedObjectTargetImpl() |
51 | 0 | { |
52 | 0 | } |
53 | |
|
54 | |
public String getName() |
55 | |
{ |
56 | 0 | if (_name != null) |
57 | |
{ |
58 | 0 | return (String) _name.getValue(FacesContext.getCurrentInstance().getELContext()); |
59 | |
} |
60 | 0 | return null; |
61 | |
} |
62 | |
|
63 | |
public List<UIComponent> getTargets(UIComponent topLevelComponent) |
64 | |
{ |
65 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
66 | 0 | String [] targetsArray = getTargets(facesContext); |
67 | |
|
68 | 0 | if (targetsArray.length > 0) |
69 | |
{ |
70 | 0 | List<UIComponent> targetsList = new ArrayList<UIComponent>(targetsArray.length); |
71 | 0 | final char separatorChar = facesContext.getNamingContainerSeparatorChar(); |
72 | 0 | UIComponent facetBase = topLevelComponent.getFacet(UIComponent.COMPOSITE_FACET_NAME); |
73 | 0 | for (String target : targetsArray) |
74 | |
{ |
75 | |
|
76 | |
|
77 | 0 | int separator = target.indexOf(separatorChar); |
78 | 0 | UIComponent innerComponent = null; |
79 | 0 | if (separator == -1) |
80 | |
{ |
81 | 0 | innerComponent = ComponentSupport.findComponentChildOrFacetFrom( |
82 | |
facetBase, target, null); |
83 | |
} |
84 | |
else |
85 | |
{ |
86 | 0 | innerComponent = ComponentSupport.findComponentChildOrFacetFrom( |
87 | |
facetBase, target.substring(0,separator), target); |
88 | |
} |
89 | |
|
90 | 0 | if (innerComponent != null) |
91 | |
{ |
92 | 0 | targetsList.add(innerComponent); |
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 | |
|
107 | |
|
108 | 0 | UIComponent innerComponent = ComponentSupport.findComponentChildOrFacetFrom( |
109 | |
topLevelComponent.getFacet(UIComponent.COMPOSITE_FACET_NAME), |
110 | |
name, null); |
111 | 0 | if (innerComponent != null) |
112 | |
{ |
113 | 0 | List<UIComponent> targetsList = new ArrayList<UIComponent>(1); |
114 | 0 | targetsList.add(innerComponent); |
115 | 0 | return targetsList; |
116 | |
} |
117 | |
} |
118 | 0 | return Collections.emptyList(); |
119 | |
} |
120 | |
} |
121 | |
|
122 | |
public String [] getTargets(FacesContext context) |
123 | |
{ |
124 | 0 | if (_targets != null) |
125 | |
{ |
126 | 0 | return StringUtils.splitShortString((String) _targets.getValue(context.getELContext()), ' '); |
127 | |
} |
128 | 0 | return org.apache.myfaces.shared.util.ArrayUtils.EMPTY_STRING_ARRAY; |
129 | |
} |
130 | |
|
131 | |
public void setName(ValueExpression ve) |
132 | |
{ |
133 | 0 | _name = ve; |
134 | 0 | } |
135 | |
|
136 | |
public void setTargets(ValueExpression ve) |
137 | |
{ |
138 | 0 | _targets = ve; |
139 | 0 | } |
140 | |
} |