1 package org.rcfaces.core.internal.taglib;
2
3 import javax.faces.application.Application;
4 import javax.faces.component.UIComponent;
5 import org.rcfaces.core.component.MenuItemComponent;
6 import org.rcfaces.core.internal.component.Properties;
7 import javax.el.ValueExpression;
8 import javax.faces.component.UIViewRoot;
9 import org.apache.commons.logging.Log;
10 import javax.servlet.jsp.tagext.Tag;
11 import org.apache.commons.logging.LogFactory;
12 import org.rcfaces.core.internal.tools.ListenersTools1_2;
13 import org.rcfaces.core.internal.tools.ListenersTools;
14 import javax.faces.context.FacesContext;
15
16 public class MenuItemTag extends ExpandableItemTag implements Tag {
17
18
19 private static final Log LOG=LogFactory.getLog(MenuItemTag.class);
20
21 private ValueExpression accessKey;
22 private ValueExpression acceleratorKey;
23 private ValueExpression styleClass;
24 private ValueExpression immediate;
25 private ValueExpression menuListeners;
26 private ValueExpression removeAllWhenShown;
27 public String getComponentType() {
28 return MenuItemComponent.COMPONENT_TYPE;
29 }
30
31 public final void setAccessKey(ValueExpression accessKey) {
32 this.accessKey = accessKey;
33 }
34
35 public final void setAcceleratorKey(ValueExpression acceleratorKey) {
36 this.acceleratorKey = acceleratorKey;
37 }
38
39 public final void setStyleClass(ValueExpression styleClass) {
40 this.styleClass = styleClass;
41 }
42
43 public final void setImmediate(ValueExpression immediate) {
44 this.immediate = immediate;
45 }
46
47 public final void setMenuListener(ValueExpression menuListeners) {
48 this.menuListeners = menuListeners;
49 }
50
51 public final void setRemoveAllWhenShown(ValueExpression removeAllWhenShown) {
52 this.removeAllWhenShown = removeAllWhenShown;
53 }
54
55 protected void setProperties(UIComponent uiComponent) {
56 if (LOG.isDebugEnabled()) {
57 if (MenuItemComponent.COMPONENT_TYPE==getComponentType()) {
58 LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
59 }
60 LOG.debug(" accessKey='"+accessKey+"'");
61 LOG.debug(" acceleratorKey='"+acceleratorKey+"'");
62 LOG.debug(" styleClass='"+styleClass+"'");
63 LOG.debug(" immediate='"+immediate+"'");
64 LOG.debug(" removeAllWhenShown='"+removeAllWhenShown+"'");
65 }
66 if ((uiComponent instanceof MenuItemComponent)==false) {
67 if (uiComponent instanceof UIViewRoot) {
68 throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
69 }
70 throw new IllegalStateException("Component specified by tag is not instanceof of 'MenuItemComponent'.");
71 }
72
73 super.setProperties(uiComponent);
74
75 MenuItemComponent component = (MenuItemComponent) uiComponent;
76 FacesContext facesContext = getFacesContext();
77
78 if (accessKey != null) {
79 if (accessKey.isLiteralText()==false) {
80 component.setValueExpression(Properties.ACCESS_KEY, accessKey);
81
82 } else {
83 component.setAccessKey(accessKey.getExpressionString());
84 }
85 }
86
87 if (acceleratorKey != null) {
88 if (acceleratorKey.isLiteralText()==false) {
89 component.setValueExpression(Properties.ACCELERATOR_KEY, acceleratorKey);
90
91 } else {
92 component.setAcceleratorKey(acceleratorKey.getExpressionString());
93 }
94 }
95
96 if (styleClass != null) {
97 if (styleClass.isLiteralText()==false) {
98 component.setValueExpression(Properties.STYLE_CLASS, styleClass);
99
100 } else {
101 component.setStyleClass(styleClass.getExpressionString());
102 }
103 }
104
105 if (immediate != null) {
106 if (immediate.isLiteralText()==false) {
107 component.setValueExpression(Properties.IMMEDIATE, immediate);
108
109 } else {
110 component.setImmediate(getBool(immediate.getExpressionString()));
111 }
112 }
113
114 if (menuListeners != null) {
115 ListenersTools1_2.parseListener(facesContext, component, ListenersTools.MENU_LISTENER_TYPE, menuListeners);
116 }
117
118 if (removeAllWhenShown != null) {
119 if (removeAllWhenShown.isLiteralText()==false) {
120 component.setValueExpression(Properties.REMOVE_ALL_WHEN_SHOWN, removeAllWhenShown);
121
122 } else {
123 component.setRemoveAllWhenShown(getBool(removeAllWhenShown.getExpressionString()));
124 }
125 }
126 }
127
128 public void release() {
129 accessKey = null;
130 acceleratorKey = null;
131 styleClass = null;
132 immediate = null;
133 menuListeners = null;
134 removeAllWhenShown = null;
135
136 super.release();
137 }
138
139 }