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 org.rcfaces.core.component.ImageButtonComponent;
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 ImageButtonTag extends ButtonTag implements Tag {
17
18
19 private static final Log LOG=LogFactory.getLog(ImageButtonTag.class);
20
21 private ValueExpression imageURL;
22 private ValueExpression disabledImageURL;
23 private ValueExpression hoverImageURL;
24 private ValueExpression selectedImageURL;
25 private ValueExpression border;
26 private ValueExpression borderType;
27 private ValueExpression textPosition;
28 private ValueExpression imageHeight;
29 private ValueExpression imageWidth;
30 public String getComponentType() {
31 return ImageButtonComponent.COMPONENT_TYPE;
32 }
33
34 public final void setImageURL(ValueExpression imageURL) {
35 this.imageURL = imageURL;
36 }
37
38 public final void setDisabledImageURL(ValueExpression disabledImageURL) {
39 this.disabledImageURL = disabledImageURL;
40 }
41
42 public final void setHoverImageURL(ValueExpression hoverImageURL) {
43 this.hoverImageURL = hoverImageURL;
44 }
45
46 public final void setSelectedImageURL(ValueExpression selectedImageURL) {
47 this.selectedImageURL = selectedImageURL;
48 }
49
50 public final void setBorder(ValueExpression border) {
51 this.border = border;
52 }
53
54 public final void setBorderType(ValueExpression borderType) {
55 this.borderType = borderType;
56 }
57
58 public final void setTextPosition(ValueExpression textPosition) {
59 this.textPosition = textPosition;
60 }
61
62 public final void setImageHeight(ValueExpression imageHeight) {
63 this.imageHeight = imageHeight;
64 }
65
66 public final void setImageWidth(ValueExpression imageWidth) {
67 this.imageWidth = imageWidth;
68 }
69
70 protected void setProperties(UIComponent uiComponent) {
71 if (LOG.isDebugEnabled()) {
72 if (ImageButtonComponent.COMPONENT_TYPE==getComponentType()) {
73 LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
74 }
75 LOG.debug(" imageURL='"+imageURL+"'");
76 LOG.debug(" disabledImageURL='"+disabledImageURL+"'");
77 LOG.debug(" hoverImageURL='"+hoverImageURL+"'");
78 LOG.debug(" selectedImageURL='"+selectedImageURL+"'");
79 LOG.debug(" border='"+border+"'");
80 LOG.debug(" borderType='"+borderType+"'");
81 LOG.debug(" textPosition='"+textPosition+"'");
82 LOG.debug(" imageHeight='"+imageHeight+"'");
83 LOG.debug(" imageWidth='"+imageWidth+"'");
84 }
85 if ((uiComponent instanceof ImageButtonComponent)==false) {
86 if (uiComponent instanceof UIViewRoot) {
87 throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
88 }
89 throw new IllegalStateException("Component specified by tag is not instanceof of 'ImageButtonComponent'.");
90 }
91
92 super.setProperties(uiComponent);
93
94 ImageButtonComponent component = (ImageButtonComponent) uiComponent;
95 FacesContext facesContext = getFacesContext();
96
97 if (imageURL != null) {
98 if (imageURL.isLiteralText()==false) {
99 component.setValueExpression(Properties.IMAGE_URL, imageURL);
100
101 } else {
102 component.setImageURL(imageURL.getExpressionString());
103 }
104 }
105
106 if (disabledImageURL != null) {
107 if (disabledImageURL.isLiteralText()==false) {
108 component.setValueExpression(Properties.DISABLED_IMAGE_URL, disabledImageURL);
109
110 } else {
111 component.setDisabledImageURL(disabledImageURL.getExpressionString());
112 }
113 }
114
115 if (hoverImageURL != null) {
116 if (hoverImageURL.isLiteralText()==false) {
117 component.setValueExpression(Properties.HOVER_IMAGE_URL, hoverImageURL);
118
119 } else {
120 component.setHoverImageURL(hoverImageURL.getExpressionString());
121 }
122 }
123
124 if (selectedImageURL != null) {
125 if (selectedImageURL.isLiteralText()==false) {
126 component.setValueExpression(Properties.SELECTED_IMAGE_URL, selectedImageURL);
127
128 } else {
129 component.setSelectedImageURL(selectedImageURL.getExpressionString());
130 }
131 }
132
133 if (border != null) {
134 if (border.isLiteralText()==false) {
135 component.setValueExpression(Properties.BORDER, border);
136
137 } else {
138 component.setBorder(getBool(border.getExpressionString()));
139 }
140 }
141
142 if (borderType != null) {
143 if (borderType.isLiteralText()==false) {
144 component.setValueExpression(Properties.BORDER_TYPE, borderType);
145
146 } else {
147 component.setBorderType(borderType.getExpressionString());
148 }
149 }
150
151 if (textPosition != null) {
152 if (textPosition.isLiteralText()==false) {
153 component.setValueExpression(Properties.TEXT_POSITION, textPosition);
154
155 } else {
156 component.setTextPosition(textPosition.getExpressionString());
157 }
158 }
159
160 if (imageHeight != null) {
161 if (imageHeight.isLiteralText()==false) {
162 component.setValueExpression(Properties.IMAGE_HEIGHT, imageHeight);
163
164 } else {
165 component.setImageHeight(getInt(imageHeight.getExpressionString()));
166 }
167 }
168
169 if (imageWidth != null) {
170 if (imageWidth.isLiteralText()==false) {
171 component.setValueExpression(Properties.IMAGE_WIDTH, imageWidth);
172
173 } else {
174 component.setImageWidth(getInt(imageWidth.getExpressionString()));
175 }
176 }
177 }
178
179 public void release() {
180 imageURL = null;
181 disabledImageURL = null;
182 hoverImageURL = null;
183 selectedImageURL = null;
184 border = null;
185 borderType = null;
186 textPosition = null;
187 imageHeight = null;
188 imageWidth = null;
189
190 super.release();
191 }
192
193 }