1
2
3
4 package org.rcfaces.core.internal.facelets;
5
6 import javax.el.ExpressionFactory;
7 import javax.el.MethodExpression;
8 import javax.el.ValueExpression;
9 import javax.faces.component.UIComponent;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.rcfaces.core.internal.capability.IComponentLifeCycle;
14 import org.rcfaces.core.internal.tools.ListenersTools;
15 import org.rcfaces.core.internal.tools.ListenersTools.IListenerType;
16 import org.rcfaces.core.internal.tools.ListenersTools1_2;
17
18 import com.sun.facelets.FaceletContext;
19 import com.sun.facelets.el.TagMethodExpression;
20 import com.sun.facelets.tag.TagAttribute;
21 import com.sun.facelets.tag.jsf.ComponentConfig;
22 import com.sun.facelets.tag.jsf.ComponentHandler;
23
24
25
26
27
28
29 public class CameliaComponentHandler0 extends ComponentHandler {
30 private static final String REVISION = "$Revision: 1.3.2.1 $";
31
32 private static final Log LOG = LogFactory
33 .getLog(CameliaComponentHandler0.class);
34
35 private static final boolean debugEnabled = LOG.isDebugEnabled();
36
37 public CameliaComponentHandler0(ComponentConfig config) {
38 super(config);
39 }
40
41 protected UIComponent createComponent(FaceletContext ctx) {
42 TagAttribute binding = getAttribute("binding");
43 if (binding == null) {
44 UIComponent component = super.createComponent(ctx);
45
46 if (component instanceof IComponentLifeCycle) {
47 IComponentLifeCycle componentLifeCycle = (IComponentLifeCycle) component;
48
49 componentLifeCycle
50 .initializePhase(ctx.getFacesContext(), false);
51 }
52
53 if (debugEnabled) {
54 LOG.debug("Create component for id '" + getId(ctx)
55 + "' returns '" + component + "'.");
56 }
57
58 return component;
59 }
60
61 ValueExpression ve = binding.getValueExpression(ctx, Object.class);
62
63 Object bindingValue = ve.getValue(ctx);
64
65 UIComponent component = super.createComponent(ctx);
66
67 if (component instanceof IComponentLifeCycle) {
68 IComponentLifeCycle componentLifeCycle = (IComponentLifeCycle) component;
69
70 componentLifeCycle.initializePhase(ctx.getFacesContext(),
71 bindingValue != null);
72 }
73
74 if (debugEnabled) {
75 LOG.debug("Create component for id '" + getId(ctx) + "' returns '"
76 + component + "'.");
77 }
78
79 return component;
80 }
81
82 protected static void actionApplyMetaData(final FaceletContext ctx,
83 UIComponent instance, String expression,
84 IListenerType defaultListenerType, final TagAttribute tagAttribute) {
85
86 ListenersTools1_2.parseAction(ctx.getFacesContext(), instance,
87 defaultListenerType, expression,
88 new ListenersTools.IMethodExpressionCreator() {
89
90 public MethodExpression create(String expression,
91 Class[] paramTypes) {
92
93 ExpressionFactory expressionFactory = ctx
94 .getExpressionFactory();
95
96 MethodExpression methodExpression = expressionFactory
97 .createMethodExpression(ctx, expression, null,
98 paramTypes);
99
100 return new TagMethodExpression(tagAttribute,
101 methodExpression);
102 }
103 });
104 }
105 }