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.jsf.core; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.util.Map; |
23 | |
import javax.el.ValueExpression; |
24 | |
import javax.faces.component.UIComponent; |
25 | |
import javax.faces.view.facelets.FaceletContext; |
26 | |
import javax.faces.view.facelets.TagAttribute; |
27 | |
import javax.faces.view.facelets.TagConfig; |
28 | |
import javax.faces.view.facelets.TagException; |
29 | |
import javax.faces.view.facelets.TagHandler; |
30 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
@JSFFaceletTag( |
38 | |
name = "f:attributes", |
39 | |
bodyContent = "empty") |
40 | |
public final class AttributesHandler extends TagHandler |
41 | |
{ |
42 | |
private final TagAttribute _value; |
43 | |
|
44 | |
public AttributesHandler(TagConfig config) |
45 | |
{ |
46 | 0 | super(config); |
47 | 0 | _value = getRequiredAttribute("value"); |
48 | 0 | } |
49 | |
|
50 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException |
51 | |
{ |
52 | 0 | if (parent == null) |
53 | |
{ |
54 | 0 | throw new TagException(this.tag, "Parent UIComponent was null"); |
55 | |
} |
56 | |
|
57 | |
|
58 | 0 | if (parent.getParent() == null) |
59 | |
{ |
60 | 0 | Map<String, Object> map = (Map<String, Object>) _value.getObject(ctx, Map.class); |
61 | 0 | Map<String, Object> attributesMap = parent.getAttributes(); |
62 | |
|
63 | 0 | for (Map.Entry<String, Object> entry : map.entrySet()) |
64 | |
{ |
65 | 0 | if (!attributesMap.containsKey(entry.getKey())) |
66 | |
{ |
67 | 0 | if (entry.getValue() instanceof ValueExpression) |
68 | |
{ |
69 | 0 | parent.setValueExpression(entry.getKey(), (ValueExpression) entry.getValue()); |
70 | |
} |
71 | |
else |
72 | |
{ |
73 | 0 | attributesMap.put(entry.getKey(), entry.getValue()); |
74 | |
} |
75 | |
} |
76 | 0 | } |
77 | |
} |
78 | 0 | } |
79 | |
} |