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.beans.PropertyDescriptor;
22
23 import javax.el.ValueExpression;
24 import javax.faces.component.UIComponent;
25 import javax.faces.view.facelets.FaceletContext;
26 import javax.faces.view.facelets.MetaRule;
27 import javax.faces.view.facelets.Metadata;
28 import javax.faces.view.facelets.MetadataTarget;
29 import javax.faces.view.facelets.TagAttribute;
30
31
32
33
34
35
36
37 final class RetargetMethodExpressionRule extends MetaRule
38 {
39 final static class RetargetValueExpressionMapper extends Metadata
40 {
41 private final TagAttribute _attr;
42
43 private final String _name;
44
45 public RetargetValueExpressionMapper(TagAttribute attr, String name)
46 {
47 this._attr = attr;
48 this._name = name;
49 }
50
51 public void applyMetadata(FaceletContext ctx, Object instance)
52 {
53 ValueExpression expr = _attr.getValueExpression(ctx, Object.class);
54 ((UIComponent) instance).getAttributes().put(_name, expr);
55 }
56 }
57
58 public final static RetargetMethodExpressionRule INSTANCE = new RetargetMethodExpressionRule();
59
60 public RetargetMethodExpressionRule()
61 {
62 super();
63 }
64
65 public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
66 {
67
68
69 if ("action".equals(name) ||
70 "actionListener".equals(name) ||
71 "validator".equals(name) ||
72 "valueChangeListener".equals(name))
73 {
74 return new RetargetValueExpressionMapper(attribute, name);
75 }
76 else
77 {
78 PropertyDescriptor propertyDescriptor = meta.getProperty(name);
79
80 if (propertyDescriptor != null &&
81 propertyDescriptor.getValue("type") == null)
82 {
83 ValueExpression methodSignatureExpression =
84 (ValueExpression) propertyDescriptor.getValue("method-signature");
85
86 if (methodSignatureExpression != null)
87 {
88 return new RetargetValueExpressionMapper(attribute, name);
89 }
90
91 ValueExpression targetAttributeNameVE =
92 (ValueExpression)propertyDescriptor.getValue("targetAttributeName");
93 if (targetAttributeNameVE != null)
94 {
95 return new RetargetValueExpressionMapper(attribute, name);
96 }
97
98
99 ValueExpression targets =
100 (ValueExpression)propertyDescriptor.getValue("targets");
101
102 if (targets != null)
103 {
104 return new RetargetValueExpressionMapper(attribute, name);
105 }
106 }
107 }
108 return null;
109 }
110 }