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 super(config);
47 _value = getRequiredAttribute("value");
48 }
49
50 public void apply(FaceletContext ctx, UIComponent parent) throws IOException
51 {
52 if (parent == null)
53 {
54 throw new TagException(this.tag, "Parent UIComponent was null");
55 }
56
57
58 if (parent.getParent() == null)
59 {
60 Map<String, Object> map = (Map<String, Object>) _value.getObject(ctx, Map.class);
61 Map<String, Object> attributesMap = parent.getAttributes();
62
63 for (Map.Entry<String, Object> entry : map.entrySet())
64 {
65 if (!attributesMap.containsKey(entry.getKey()))
66 {
67 if (entry.getValue() instanceof ValueExpression)
68 {
69 parent.setValueExpression(entry.getKey(), (ValueExpression) entry.getValue());
70 }
71 else
72 {
73 attributesMap.put(entry.getKey(), entry.getValue());
74 }
75 }
76 }
77 }
78 }
79 }