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.internal.component.Properties;
6 import javax.el.ValueExpression;
7 import javax.faces.component.UIViewRoot;
8 import org.apache.commons.logging.Log;
9 import javax.servlet.jsp.tagext.Tag;
10 import org.apache.commons.logging.LogFactory;
11 import org.rcfaces.core.internal.tools.ListenersTools1_2;
12 import org.rcfaces.core.component.AbstractMenuComponent;
13 import org.rcfaces.core.internal.tools.ListenersTools;
14 import javax.faces.context.FacesContext;
15
16 public abstract class AbstractMenuTag extends AbstractConverterCommandTag implements Tag {
17
18
19 private static final Log LOG=LogFactory.getLog(AbstractMenuTag.class);
20
21 private ValueExpression selectionListeners;
22 private ValueExpression checkListeners;
23 private ValueExpression checkedValues;
24 private ValueExpression readOnly;
25 private ValueExpression removeAllWhenShown;
26 public final void setSelectionListener(ValueExpression selectionListeners) {
27 this.selectionListeners = selectionListeners;
28 }
29
30 public final void setCheckListener(ValueExpression checkListeners) {
31 this.checkListeners = checkListeners;
32 }
33
34 public final void setCheckedValues(ValueExpression checkedValues) {
35 this.checkedValues = checkedValues;
36 }
37
38 public final void setReadOnly(ValueExpression readOnly) {
39 this.readOnly = readOnly;
40 }
41
42 public final void setRemoveAllWhenShown(ValueExpression removeAllWhenShown) {
43 this.removeAllWhenShown = removeAllWhenShown;
44 }
45
46 protected void setProperties(UIComponent uiComponent) {
47 if (LOG.isDebugEnabled()) {
48 LOG.debug(" checkedValues='"+checkedValues+"'");
49 LOG.debug(" readOnly='"+readOnly+"'");
50 LOG.debug(" removeAllWhenShown='"+removeAllWhenShown+"'");
51 }
52 if ((uiComponent instanceof AbstractMenuComponent)==false) {
53 if (uiComponent instanceof UIViewRoot) {
54 throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
55 }
56 throw new IllegalStateException("Component specified by tag is not instanceof of 'AbstractMenuComponent'.");
57 }
58
59 super.setProperties(uiComponent);
60
61 AbstractMenuComponent component = (AbstractMenuComponent) uiComponent;
62 FacesContext facesContext = getFacesContext();
63
64 if (selectionListeners != null) {
65 ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, selectionListeners);
66 }
67
68 if (checkListeners != null) {
69 ListenersTools1_2.parseListener(facesContext, component, ListenersTools.CHECK_LISTENER_TYPE, checkListeners);
70 }
71
72 if (checkedValues != null) {
73 component.setValueExpression(Properties.CHECKED_VALUES, checkedValues);
74 }
75
76 if (readOnly != null) {
77 if (readOnly.isLiteralText()==false) {
78 component.setValueExpression(Properties.READ_ONLY, readOnly);
79
80 } else {
81 component.setReadOnly(getBool(readOnly.getExpressionString()));
82 }
83 }
84
85 if (removeAllWhenShown != null) {
86 if (removeAllWhenShown.isLiteralText()==false) {
87 component.setValueExpression(Properties.REMOVE_ALL_WHEN_SHOWN, removeAllWhenShown);
88
89 } else {
90 component.setRemoveAllWhenShown(getBool(removeAllWhenShown.getExpressionString()));
91 }
92 }
93 }
94
95 public void release() {
96 selectionListeners = null;
97 checkListeners = null;
98 checkedValues = null;
99 readOnly = null;
100 removeAllWhenShown = null;
101
102 super.release();
103 }
104
105 }