View Javadoc

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.AbstractItemComponent;
13  import org.rcfaces.core.internal.tools.ListenersTools;
14  import javax.faces.context.FacesContext;
15  
16  public abstract class AbstractItemTag extends CameliaTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(AbstractItemTag.class);
20  
21  	private ValueExpression disabled;
22  	private ValueExpression unlockedClientAttributeNames;
23  	private ValueExpression itemValue;
24  	private ValueExpression itemLabel;
25  	private ValueExpression itemDescription;
26  	private ValueExpression itemDisabled;
27  	public final void setDisabled(ValueExpression disabled) {
28  		this.disabled = disabled;
29  	}
30  
31  	public final void setUnlockedClientAttributeNames(ValueExpression unlockedClientAttributeNames) {
32  		this.unlockedClientAttributeNames = unlockedClientAttributeNames;
33  	}
34  
35  	public final void setItemValue(ValueExpression itemValue) {
36  		this.itemValue = itemValue;
37  	}
38  
39  	public final void setItemLabel(ValueExpression itemLabel) {
40  		this.itemLabel = itemLabel;
41  	}
42  
43  	public final void setItemDescription(ValueExpression itemDescription) {
44  		this.itemDescription = itemDescription;
45  	}
46  
47  	public final void setItemDisabled(ValueExpression itemDisabled) {
48  		this.itemDisabled = itemDisabled;
49  	}
50  
51  	protected void setProperties(UIComponent uiComponent) {
52  		if (LOG.isDebugEnabled()) {
53  			LOG.debug("  disabled='"+disabled+"'");
54  			LOG.debug("  unlockedClientAttributeNames='"+unlockedClientAttributeNames+"'");
55  			LOG.debug("  itemValue='"+itemValue+"'");
56  			LOG.debug("  itemLabel='"+itemLabel+"'");
57  			LOG.debug("  itemDescription='"+itemDescription+"'");
58  			LOG.debug("  itemDisabled='"+itemDisabled+"'");
59  		}
60  		if ((uiComponent instanceof AbstractItemComponent)==false) {
61  			if (uiComponent instanceof UIViewRoot) {
62  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
63  			}
64  			throw new IllegalStateException("Component specified by tag is not instanceof of 'AbstractItemComponent'.");
65  		}
66  
67  		super.setProperties(uiComponent);
68  
69  		AbstractItemComponent component = (AbstractItemComponent) uiComponent;
70  		FacesContext facesContext = getFacesContext();
71  
72  		if (disabled != null) {
73  			if (disabled.isLiteralText()==false) {
74  				component.setValueExpression(Properties.DISABLED, disabled);
75  
76  			} else {
77  				component.setDisabled(getBool(disabled.getExpressionString()));
78  			}
79  		}
80  
81  		if (unlockedClientAttributeNames != null) {
82  			if (unlockedClientAttributeNames.isLiteralText()==false) {
83  				component.setValueExpression(Properties.UNLOCKED_CLIENT_ATTRIBUTE_NAMES, unlockedClientAttributeNames);
84  
85  			} else {
86  				component.setUnlockedClientAttributeNames(unlockedClientAttributeNames.getExpressionString());
87  			}
88  		}
89  
90  		if (itemValue != null) {
91  			if (itemValue.isLiteralText()==false) {
92  				component.setValueExpression(Properties.ITEM_VALUE, itemValue);
93  
94  			} else {
95  				component.setItemValue(itemValue.getExpressionString());
96  			}
97  		}
98  
99  		if (itemLabel != null) {
100 			if (itemLabel.isLiteralText()==false) {
101 				component.setValueExpression(Properties.ITEM_LABEL, itemLabel);
102 
103 			} else {
104 				component.setItemLabel(itemLabel.getExpressionString());
105 			}
106 		}
107 
108 		if (itemDescription != null) {
109 			if (itemDescription.isLiteralText()==false) {
110 				component.setValueExpression(Properties.ITEM_DESCRIPTION, itemDescription);
111 
112 			} else {
113 				component.setItemDescription(itemDescription.getExpressionString());
114 			}
115 		}
116 
117 		if (itemDisabled != null) {
118 			if (itemDisabled.isLiteralText()==false) {
119 				component.setValueExpression(Properties.ITEM_DISABLED, itemDisabled);
120 
121 			} else {
122 				component.setItemDisabled(getBool(itemDisabled.getExpressionString()));
123 			}
124 		}
125 	}
126 
127 	public void release() {
128 		disabled = null;
129 		unlockedClientAttributeNames = null;
130 		itemValue = null;
131 		itemLabel = null;
132 		itemDescription = null;
133 		itemDisabled = null;
134 
135 		super.release();
136 	}
137 
138 }