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 org.rcfaces.core.component.UIImageItemComponent;
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 UIImageItemTag extends SelectItemTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(UIImageItemTag.class);
20  
21  	private ValueExpression visible;
22  	private ValueExpression disabledImageURL;
23  	private ValueExpression hoverImageURL;
24  	private ValueExpression selectedImageURL;
25  	private ValueExpression imageURL;
26  	private ValueExpression alternateText;
27  	private ValueExpression rendered;
28  	public String getComponentType() {
29  		return UIImageItemComponent.COMPONENT_TYPE;
30  	}
31  
32  	public final void setVisible(ValueExpression visible) {
33  		this.visible = visible;
34  	}
35  
36  	public final void setDisabledImageURL(ValueExpression disabledImageURL) {
37  		this.disabledImageURL = disabledImageURL;
38  	}
39  
40  	public final void setHoverImageURL(ValueExpression hoverImageURL) {
41  		this.hoverImageURL = hoverImageURL;
42  	}
43  
44  	public final void setSelectedImageURL(ValueExpression selectedImageURL) {
45  		this.selectedImageURL = selectedImageURL;
46  	}
47  
48  	public final void setImageURL(ValueExpression imageURL) {
49  		this.imageURL = imageURL;
50  	}
51  
52  	public final void setAlternateText(ValueExpression alternateText) {
53  		this.alternateText = alternateText;
54  	}
55  
56  	public final void setRendered(ValueExpression rendered) {
57  		this.rendered = rendered;
58  	}
59  
60  	protected void setProperties(UIComponent uiComponent) {
61  		if (LOG.isDebugEnabled()) {
62  			if (UIImageItemComponent.COMPONENT_TYPE==getComponentType()) {
63  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
64  			}
65  			LOG.debug("  visible='"+visible+"'");
66  			LOG.debug("  disabledImageURL='"+disabledImageURL+"'");
67  			LOG.debug("  hoverImageURL='"+hoverImageURL+"'");
68  			LOG.debug("  selectedImageURL='"+selectedImageURL+"'");
69  			LOG.debug("  imageURL='"+imageURL+"'");
70  			LOG.debug("  alternateText='"+alternateText+"'");
71  			LOG.debug("  rendered='"+rendered+"'");
72  		}
73  		if ((uiComponent instanceof UIImageItemComponent)==false) {
74  			if (uiComponent instanceof UIViewRoot) {
75  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
76  			}
77  			throw new IllegalStateException("Component specified by tag is not instanceof of 'UIImageItemComponent'.");
78  		}
79  
80  		super.setProperties(uiComponent);
81  
82  		UIImageItemComponent component = (UIImageItemComponent) uiComponent;
83  		FacesContext facesContext = getFacesContext();
84  
85  		if (visible != null) {
86  			if (visible.isLiteralText()==false) {
87  				component.setValueExpression(Properties.VISIBLE, visible);
88  
89  			} else {
90  				component.setVisible(getBool(visible.getExpressionString()));
91  			}
92  		}
93  
94  		if (disabledImageURL != null) {
95  			if (disabledImageURL.isLiteralText()==false) {
96  				component.setValueExpression(Properties.DISABLED_IMAGE_URL, disabledImageURL);
97  
98  			} else {
99  				component.setDisabledImageURL(disabledImageURL.getExpressionString());
100 			}
101 		}
102 
103 		if (hoverImageURL != null) {
104 			if (hoverImageURL.isLiteralText()==false) {
105 				component.setValueExpression(Properties.HOVER_IMAGE_URL, hoverImageURL);
106 
107 			} else {
108 				component.setHoverImageURL(hoverImageURL.getExpressionString());
109 			}
110 		}
111 
112 		if (selectedImageURL != null) {
113 			if (selectedImageURL.isLiteralText()==false) {
114 				component.setValueExpression(Properties.SELECTED_IMAGE_URL, selectedImageURL);
115 
116 			} else {
117 				component.setSelectedImageURL(selectedImageURL.getExpressionString());
118 			}
119 		}
120 
121 		if (imageURL != null) {
122 			if (imageURL.isLiteralText()==false) {
123 				component.setValueExpression(Properties.IMAGE_URL, imageURL);
124 
125 			} else {
126 				component.setImageURL(imageURL.getExpressionString());
127 			}
128 		}
129 
130 		if (alternateText != null) {
131 			if (alternateText.isLiteralText()==false) {
132 				component.setValueExpression(Properties.ALTERNATE_TEXT, alternateText);
133 
134 			} else {
135 				component.setAlternateText(alternateText.getExpressionString());
136 			}
137 		}
138 
139 		if (rendered != null) {
140 			if (rendered.isLiteralText()==false) {
141 				component.setValueExpression(Properties.RENDERED, rendered);
142 
143 			} else {
144 				component.setRendered(getBool(rendered.getExpressionString()));
145 			}
146 		}
147 	}
148 
149 	public void release() {
150 		visible = null;
151 		disabledImageURL = null;
152 		hoverImageURL = null;
153 		selectedImageURL = null;
154 		imageURL = null;
155 		alternateText = null;
156 		rendered = null;
157 
158 		super.release();
159 	}
160 
161 }