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.internal.tools.ListenersTools;
13  import org.rcfaces.core.component.KeyLabelComponent;
14  import javax.faces.context.FacesContext;
15  
16  public class KeyLabelTag extends AbstractOutputTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(KeyLabelTag.class);
20  
21  	private ValueExpression filterProperties;
22  	private ValueExpression selectedStyleClass;
23  	private ValueExpression parentsStyleClass;
24  	private ValueExpression showParents;
25  	public String getComponentType() {
26  		return KeyLabelComponent.COMPONENT_TYPE;
27  	}
28  
29  	public final void setFilterProperties(ValueExpression filterProperties) {
30  		this.filterProperties = filterProperties;
31  	}
32  
33  	public final void setSelectedStyleClass(ValueExpression selectedStyleClass) {
34  		this.selectedStyleClass = selectedStyleClass;
35  	}
36  
37  	public final void setParentsStyleClass(ValueExpression parentsStyleClass) {
38  		this.parentsStyleClass = parentsStyleClass;
39  	}
40  
41  	public final void setShowParents(ValueExpression showParents) {
42  		this.showParents = showParents;
43  	}
44  
45  	protected void setProperties(UIComponent uiComponent) {
46  		if (LOG.isDebugEnabled()) {
47  			if (KeyLabelComponent.COMPONENT_TYPE==getComponentType()) {
48  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
49  			}
50  			LOG.debug("  filterProperties='"+filterProperties+"'");
51  			LOG.debug("  selectedStyleClass='"+selectedStyleClass+"'");
52  			LOG.debug("  parentsStyleClass='"+parentsStyleClass+"'");
53  			LOG.debug("  showParents='"+showParents+"'");
54  		}
55  		if ((uiComponent instanceof KeyLabelComponent)==false) {
56  			if (uiComponent instanceof UIViewRoot) {
57  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
58  			}
59  			throw new IllegalStateException("Component specified by tag is not instanceof of 'KeyLabelComponent'.");
60  		}
61  
62  		super.setProperties(uiComponent);
63  
64  		KeyLabelComponent component = (KeyLabelComponent) uiComponent;
65  		FacesContext facesContext = getFacesContext();
66  
67  		if (filterProperties != null) {
68  			if (filterProperties.isLiteralText()==false) {
69  				component.setValueExpression(Properties.FILTER_PROPERTIES, filterProperties);
70  
71  			} else {
72  				component.setFilterProperties(filterProperties.getExpressionString());
73  			}
74  		}
75  
76  		if (selectedStyleClass != null) {
77  			if (selectedStyleClass.isLiteralText()==false) {
78  				component.setValueExpression(Properties.SELECTED_STYLE_CLASS, selectedStyleClass);
79  
80  			} else {
81  				component.setSelectedStyleClass(selectedStyleClass.getExpressionString());
82  			}
83  		}
84  
85  		if (parentsStyleClass != null) {
86  			if (parentsStyleClass.isLiteralText()==false) {
87  				component.setValueExpression(Properties.PARENTS_STYLE_CLASS, parentsStyleClass);
88  
89  			} else {
90  				component.setParentsStyleClass(parentsStyleClass.getExpressionString());
91  			}
92  		}
93  
94  		if (showParents != null) {
95  			if (showParents.isLiteralText()==false) {
96  				component.setValueExpression(Properties.SHOW_PARENTS, showParents);
97  
98  			} else {
99  				component.setShowParents(getBool(showParents.getExpressionString()));
100 			}
101 		}
102 	}
103 
104 	public void release() {
105 		filterProperties = null;
106 		selectedStyleClass = null;
107 		parentsStyleClass = null;
108 		showParents = null;
109 
110 		super.release();
111 	}
112 
113 }