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 javax.el.MethodExpression;
22 import javax.faces.component.ActionSource;
23 import javax.faces.component.ActionSource2;
24 import javax.faces.view.facelets.ComponentConfig;
25 import javax.faces.view.facelets.ComponentHandler;
26 import javax.faces.view.facelets.FaceletContext;
27 import javax.faces.view.facelets.MetaRule;
28 import javax.faces.view.facelets.MetaRuleset;
29 import javax.faces.view.facelets.Metadata;
30 import javax.faces.view.facelets.MetadataTarget;
31 import javax.faces.view.facelets.TagAttribute;
32
33 import org.apache.myfaces.view.facelets.tag.jsf.ActionSourceRule;
34
35 public class SimpleComponentTagHandler extends ComponentHandler
36 {
37
38 public SimpleComponentTagHandler(ComponentConfig config)
39 {
40 super(config);
41
42 }
43
44 @Override
45 protected MetaRuleset createMetaRuleset(Class type)
46 {
47 return super.createMetaRuleset(type).addRule(new CustomMethodRule());
48 }
49
50 public final class CustomMethodRule extends MetaRule {
51
52 @Override
53 public Metadata applyRule(String name, TagAttribute attribute,
54 MetadataTarget meta)
55 {
56 if (meta.isTargetInstanceOf(SimpleComponent.class))
57 {
58 if ("customMethod".equals(name))
59 {
60 return new SimpleMethodMapper(attribute);
61 }
62 }
63 return null;
64 }
65
66 }
67
68 final static class SimpleMethodMapper extends Metadata
69 {
70 private final TagAttribute _attr;
71
72 public final static Class<?>[] CUSTOM_METHOD_SIG = new Class[]{String.class};
73
74 public SimpleMethodMapper(TagAttribute attr)
75 {
76 this._attr = attr;
77 }
78
79 public void applyMetadata(FaceletContext ctx, Object instance)
80 {
81 MethodExpression expr = _attr.getMethodExpression(ctx, null, CUSTOM_METHOD_SIG);
82 ((SimpleComponent) instance).setCustomMethod(expr);
83 }
84 }
85
86 }