1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import org.dbforms.event.AbstractWebEvent;
27 import org.dbforms.event.eventtype.EventType;
28
29 import org.dbforms.util.Util;
30
31 import java.util.Vector;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.jsp.JspException;
35
36
37
38 /***
39 * Abstract base class for the various input tags. original author Craig R.
40 * McClanahan original author Don Clasen,
41 *
42 * @author Joachim Peer (modified this class for DbForms-Project)
43 */
44 public abstract class AbstractDbBaseInputTag extends AbstractDbBaseHandlerTag {
45 /***
46 * The number of character columns for this field, or negative for no limit.
47 */
48 private String cols = null;
49
50 /*** DOCUMENT ME! */
51 private java.lang.String hidden = "false";
52
53 /*** The maximum number of characters allowed, or negative for no limit. */
54 private String maxlength = null;
55
56 /*** DOCUMENT ME! */
57 private java.lang.String overrideValue;
58
59 /*** The number of rows for this field, or negative for no limit. */
60 private String rows = null;
61
62 /***
63 * Set the number of columns for this field.
64 *
65 * @param cols The new number of columns
66 */
67 public void setCols(String cols) {
68 this.cols = cols;
69 }
70
71
72
73
74 /***
75 * Return the number of columns for this field.
76 *
77 * @return DOCUMENT ME!
78 */
79 public String getCols() {
80 return (this.cols);
81 }
82
83
84 /***
85 * Insert the method's description here. Creation date: (2001-06-26
86 * 16:19:01)
87 *
88 * @param newHidden java.lang.String
89 */
90 public void setHidden(java.lang.String newHidden) {
91 hidden = newHidden;
92 }
93
94
95 /***
96 * Set the maximum length allowed.
97 *
98 * @param maxlength The new maximum length
99 */
100 public void setMaxlength(String maxlength) {
101 this.maxlength = maxlength;
102 }
103
104
105 /***
106 * Return the maximum length allowed.
107 *
108 * @return DOCUMENT ME!
109 */
110 public String getMaxlength() {
111 return (this.maxlength);
112 }
113
114
115 /***
116 * Insert the method's description here. Creation date: (2001-06-27
117 * 17:44:16)
118 *
119 * @param newOverrideValue java.lang.String
120 */
121 public void setOverrideValue(java.lang.String newOverrideValue) {
122 overrideValue = newOverrideValue;
123 }
124
125
126 /***
127 * Insert the method's description here. Creation date: (2001-06-27
128 * 17:44:16)
129 *
130 * @return java.lang.String
131 */
132 public java.lang.String getOverrideValue() {
133 return overrideValue;
134 }
135
136
137 /***
138 * Set the number of rows for this field.
139 *
140 * @param rows The new number of rows
141 */
142 public void setRows(String rows) {
143 this.rows = rows;
144 }
145
146
147 /***
148 * Return the number of rows for this field.
149 *
150 * @return DOCUMENT ME!
151 */
152 public String getRows() {
153 return (this.rows);
154 }
155
156
157 /***
158 * Set the size of this field (synonym for <code>setCols()</code>).
159 *
160 * @param size The new size
161 */
162 public void setSize(String size) {
163 setCols(size);
164 }
165
166
167 /***
168 * Return the size of this field (synonym for <code>getCols()</code>).
169 *
170 * @return DOCUMENT ME!
171 */
172 public String getSize() {
173 return (getCols());
174 }
175
176
177 /***
178 * Process the end of this tag. The default implementation does nothing.
179 *
180 * @return DOCUMENT ME!
181 *
182 * @exception JspException if a JSP exception has occurred
183 */
184 public int doEndTag() throws JspException {
185 return EVAL_PAGE;
186 }
187
188
189 /***
190 * DOCUMENT ME!
191 */
192 public void doFinally() {
193 cols = null;
194 maxlength = null;
195 rows = null;
196 super.doFinally();
197 }
198
199
200
201
202 /***
203 * Process the start of this tag. The default implementation does nothing.
204 *
205 * @return DOCUMENT ME!
206 *
207 * @exception JspException if a JSP exception has occurred
208 */
209 public int doStartTag() throws JspException {
210 if (hasReadOnlySet() || getParentForm()
211 .hasReadOnlySet()) {
212 String onFocus = (getOnFocus() != null) ? getOnFocus()
213 : "";
214
215 if (onFocus.lastIndexOf(";") != (onFocus.length() - 1)) {
216 onFocus += ";";
217 }
218
219 setOnFocus(onFocus + "this.blur();");
220 }
221
222 return EVAL_BODY_BUFFERED;
223 }
224
225
226 /***
227 * Insert the method's description here. Creation date: (2001-06-26
228 * 16:19:01)
229 *
230 * @return java.lang.String
231 */
232 public boolean hasHiddenSet() {
233 return Util.getTrue(hidden);
234 }
235
236
237 /***
238 * gets the formfield value
239 *
240 * @return String
241 */
242 protected String getFormFieldValue() {
243 String res;
244
245
246
247
248 HttpServletRequest request = (HttpServletRequest) this.pageContext
249 .getRequest();
250 Vector errors = (Vector) request.getAttribute("errors");
251 AbstractWebEvent we = getParentForm()
252 .getWebEvent();
253
254 if ((this.getOverrideValue() != null)
255 && !((getParentForm()
256 .hasRedisplayFieldsOnErrorSet()
257 && (errors != null) && (errors.size() > 0))
258 || ((we != null)
259 && (we.getType().equals(EventType.EVENT_NAVIGATION_RELOAD))))) {
260 res = getOverrideValue();
261 } else
262 {
263 res = super.getFormFieldValue();
264 }
265
266 return res;
267 }
268
269
270 /***
271 * DOCUMENT ME!
272 *
273 * @return DOCUMENT ME!
274 */
275 protected String prepareKeys() {
276 StringBuffer tagBuf = new StringBuffer();
277
278 if (getAccessKey() != null) {
279 tagBuf.append(" accesskey=\"");
280 tagBuf.append(getAccessKey());
281 tagBuf.append("\"");
282 }
283
284 if (getTabIndex() != null) {
285 tagBuf.append(" tabindex=\"");
286 tagBuf.append(getTabIndex());
287 tagBuf.append("\"");
288 }
289
290 return tagBuf.toString();
291 }
292
293
294 /***
295 * DOCUMENT ME!
296 *
297 * @return DOCUMENT ME!
298 */
299 protected String prepareName() {
300 StringBuffer tagBuf = new StringBuffer();
301 tagBuf.append("name=\"");
302 tagBuf.append(getFormFieldName());
303 tagBuf.append("\"");
304
305 return tagBuf.toString();
306 }
307
308
309 /***
310 * DOCUMENT ME!
311 *
312 * @return DOCUMENT ME!
313 */
314 protected String prepareSize() {
315 StringBuffer tagBuf = new StringBuffer();
316
317 if (getMaxlength() != null) {
318 tagBuf.append(" maxlength=\"");
319 tagBuf.append(getMaxlength());
320 tagBuf.append("\"");
321 }
322
323 if (getCols() != null) {
324 tagBuf.append(" size=\"");
325 tagBuf.append(getCols());
326 tagBuf.append("\"");
327 }
328
329 return tagBuf.toString();
330 }
331
332
333 /***
334 * DOCUMENT ME!
335 *
336 * @return DOCUMENT ME!
337 */
338 protected String prepareType() {
339 return hasHiddenSet() ? "type=\"hidden\" "
340 : "type=\"text\" ";
341 }
342
343
344 /***
345 * DOCUMENT ME!
346 *
347 * @return DOCUMENT ME!
348 */
349 protected String prepareValue() {
350 StringBuffer tagBuf = new StringBuffer();
351 tagBuf.append(" value=\"");
352 tagBuf.append(escapeHTML(getFormFieldValue()));
353 tagBuf.append("\" ");
354
355 return tagBuf.toString();
356 }
357
358
359 /***
360 * writes out all hidden fields for the input fields
361 */
362 protected void writeOutSpecialValues() throws JspException {
363 super.writeOutSpecialValues();
364
365 try {
366 pageContext.getOut()
367 .write(renderPatternHtmlInputField());
368 } catch (java.io.IOException ioe) {
369 throw new JspException("IO Error: " + ioe.getMessage());
370 }
371 }
372 }