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.ui;
20
21 import java.beans.Introspector;
22 import java.beans.PropertyDescriptor;
23 import java.util.HashSet;
24 import java.util.Map;
25 import java.util.Set;
26
27 import javax.faces.component.UIComponent;
28 import javax.faces.view.facelets.ComponentConfig;
29 import javax.faces.view.facelets.ComponentHandler;
30 import javax.faces.view.facelets.FaceletContext;
31 import javax.faces.view.facelets.MetaRuleset;
32 import javax.faces.view.facelets.Metadata;
33 import javax.faces.view.facelets.TagAttribute;
34
35
36
37
38
39 public class RepeatHandler extends ComponentHandler
40 {
41
42 public RepeatHandler(ComponentConfig config)
43 {
44 super(config);
45 }
46
47 protected MetaRuleset createMetaRuleset(Class type)
48 {
49 MetaRuleset meta = super.createMetaRuleset(type);
50
51 if (!UILibrary.NAMESPACE.equals(this.tag.getNamespace()) &&
52 !UILibrary.ALIAS_NAMESPACE.equals(this.tag.getNamespace()))
53 {
54 meta.add(new TagMetaData(type));
55 }
56
57 meta.alias("class", "styleClass");
58
59 return meta;
60 }
61
62 private class TagMetaData extends Metadata
63 {
64 private final String[] _attrs;
65
66 public TagMetaData(Class<?> type)
67 {
68 Set<String> names = new HashSet<String>();
69 for (TagAttribute attribute : tag.getAttributes().getAll())
70 {
71 if ("class".equals(attribute.getLocalName()))
72 {
73 names.add("styleClass");
74 }
75 else
76 {
77 names.add(attribute.getLocalName());
78 }
79 }
80
81 try
82 {
83 for (PropertyDescriptor descriptor : Introspector.getBeanInfo(type).getPropertyDescriptors())
84 {
85 if (descriptor.getWriteMethod() != null)
86 {
87 names.remove(descriptor.getName());
88 }
89 }
90 }
91 catch (Exception e)
92 {
93
94 }
95
96 _attrs = names.toArray(new String[names.size()]);
97 }
98
99 public void applyMetadata(FaceletContext ctx, Object instance)
100 {
101 UIComponent component = (UIComponent) instance;
102 Map<String, Object> attrs = component.getAttributes();
103 attrs.put("alias.element", tag.getQName());
104 if (_attrs.length > 0)
105 {
106 attrs.put("alias.attributes", _attrs);
107 }
108 }
109 }
110 }