1
2
3
4
5 package ecar.taglib.util;
6
7 import javax.servlet.jsp.JspException;
8 import javax.servlet.jsp.JspWriter;
9 import javax.servlet.jsp.tagext.Tag;
10 import javax.servlet.jsp.tagext.TagSupport;
11
12 import org.apache.log4j.Logger;
13
14
15
16
17
18
19
20 public class InputTag extends TagSupport {
21
22
23
24
25 private static final long serialVersionUID = -3448973752966957420L;
26
27 private Logger logger = Logger.getLogger(this.getClass());
28
29
30 private final String ASPAS = "\"";
31 private final String TYPE = " type=";
32 private final String NAME = " name=";
33 private final String VALUE = " value=";
34 private final String SIZE = " size=";
35 private final String MAXLENGTH = " maxlength=";
36 private final String EXTRA = " ";
37 private final String ALIGN = " align=";
38 private final String COLSPAN = " colspan=";
39 private final String ROWSPAN = " rowspan=";
40 private final String LABEL = "";
41 private final String END_LABEL = " ";
42 private final String INPUT = " <input ";
43 private final String END_INPUT = " > ";
44 private final String TD = " <td ";
45 private final String END_TD = "</td>";
46 private final String CLASS = " class=";
47 private final String WIDTH = " width=";
48
49
50 private String itype = "text";
51 private String iname = "inputTag";
52 private String ivalue = "";
53 private String isize = "10";
54 private String imaxlength = "10";
55 private String iextra = null;
56
57 private String ialign = "left";
58 private String icolspan = null;
59 private String irowspan = null;
60 private String iclass = null;
61 private String iwidth = "70%";
62
63
64 private String lname = "";
65
66 private String lalign = "right";
67 private String lcolspan = null;
68 private String lrowspan = null;
69 private String lclass = null;
70 private String lwidth = "30%";
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public int doStartTag() throws JspException {
86 JspWriter writer = this.pageContext.getOut();
87
88 StringBuffer input = new StringBuffer();
89 StringBuffer tdLabel = new StringBuffer();
90 StringBuffer tdInput = new StringBuffer();
91
92
93 if (this.getItype() != null)
94 input.append(TYPE).append(ASPAS).append(this.getItype()).append(ASPAS);
95
96 if (this.getIname() != null)
97 input.append(NAME).append(ASPAS).append(this.getIname()).append(ASPAS);
98
99 if (this.getIsize() != null)
100 input.append(SIZE).append(ASPAS).append(this.getIsize()).append(ASPAS);
101
102 if (this.getImaxlength() != null)
103 input.append(MAXLENGTH).append(ASPAS).append(this.getImaxlength()).append(ASPAS);
104
105 if (this.getIvalue() != null)
106 input.append(VALUE).append(ASPAS).append(this.getIvalue()).append(ASPAS);
107
108 if (this.getIextra() != null)
109 input.append(EXTRA).append(ASPAS).append(this.getIextra()).append(ASPAS);
110
111
112 if (this.getIalign() != null)
113 tdInput.append(ALIGN).append(ASPAS).append(this.getIalign()).append(ASPAS);
114
115 if (this.getIcolspan() != null)
116 tdInput.append(COLSPAN).append(ASPAS).append(this.getIcolspan()).append(ASPAS);
117
118 if (this.getIrowspan() != null)
119 tdInput.append(ROWSPAN).append(ASPAS).append(this.getIrowspan()).append(ASPAS);
120
121 if (this.getIclass() != null)
122 tdInput.append(CLASS).append(ASPAS).append(this.getIclass()).append(ASPAS);
123
124 if (this.getIwidth() != null)
125 tdInput.append(WIDTH).append(ASPAS).append(this.getIwidth()).append(ASPAS);
126
127
128 if (this.getLalign() != null)
129 tdLabel.append(ALIGN).append(ASPAS).append(this.getLalign()).append(ASPAS);
130
131 if (this.getLcolspan() != null)
132 tdLabel.append(COLSPAN).append(ASPAS).append(this.getLcolspan()).append(ASPAS);
133
134 if (this.getLrowspan() != null)
135 tdLabel.append(ROWSPAN).append(ASPAS).append(this.getLrowspan()).append(ASPAS);
136
137 if (this.getLclass() != null)
138 tdLabel.append(CLASS).append(ASPAS).append(this.getLclass()).append(ASPAS);
139
140 if (this.getLwidth() != null)
141 tdLabel.append(WIDTH).append(ASPAS).append(this.getLwidth()).append(ASPAS);
142
143 try {
144 writer.println("<tr>");
145
146 writer.println(TD + tdLabel + ">");
147 writer.println(LABEL + this.getLname() + END_LABEL);
148 writer.println(END_TD);
149
150 writer.println(TD + tdInput + ">");
151 writer.println(INPUT + input + END_INPUT);
152 writer.println(END_TD);
153
154 writer.println("</tr>");
155 } catch (Exception e) {
156 logger.error(e);
157 }
158 return Tag.SKIP_BODY;
159 }
160
161
162
163
164
165
166
167
168
169
170 public int doEndTag() throws JspException {
171 return Tag.EVAL_PAGE;
172 }
173
174
175
176
177
178
179
180
181
182 public String getIalign() {
183 return ialign;
184 }
185
186
187
188
189
190
191
192
193
194 public void setIalign(String ialign) {
195 this.ialign = ialign;
196 }
197
198
199
200
201
202
203
204
205
206 public String getIclass() {
207 return iclass;
208 }
209
210
211
212
213
214
215
216
217
218 public void setIclass(String iclass) {
219 this.iclass = iclass;
220 }
221
222
223
224
225
226
227
228
229
230 public String getIcolspan() {
231 return icolspan;
232 }
233
234
235
236
237
238
239
240
241
242 public void setIcolspan(String icolspan) {
243 this.icolspan = icolspan;
244 }
245
246
247
248
249
250
251
252
253
254 public String getIextra() {
255 return iextra;
256 }
257
258
259
260
261
262
263
264
265
266 public void setIextra(String iextra) {
267 this.iextra = iextra;
268 }
269
270
271
272
273
274
275
276
277
278 public String getImaxlength() {
279 return imaxlength;
280 }
281
282
283
284
285
286
287
288
289
290 public void setImaxlength(String imaxlength) {
291 this.imaxlength = imaxlength;
292 }
293
294
295
296
297
298
299
300
301
302 public String getIname() {
303 return iname;
304 }
305
306
307
308
309
310
311
312
313
314 public void setIname(String iname) {
315 this.iname = iname;
316 }
317
318
319
320
321
322
323
324
325
326 public String getIrowspan() {
327 return irowspan;
328 }
329
330
331
332
333
334
335
336
337
338 public void setIrowspan(String irowspan) {
339 this.irowspan = irowspan;
340 }
341
342
343
344
345
346
347
348
349
350 public String getIsize() {
351 return isize;
352 }
353
354
355
356
357
358
359
360
361
362 public void setIsize(String isize) {
363 this.isize = isize;
364 }
365
366
367
368
369
370
371
372
373
374 public String getItype() {
375 return itype;
376 }
377
378
379
380
381
382
383
384
385
386 public void setItype(String itype) {
387 this.itype = itype;
388 }
389
390
391
392
393
394
395
396
397
398 public String getIvalue() {
399 return ivalue;
400 }
401
402
403
404
405
406
407
408
409
410 public void setIvalue(String ivalue) {
411 this.ivalue = ivalue;
412 }
413
414
415
416
417
418
419
420
421
422 public String getLalign() {
423 return lalign;
424 }
425
426
427
428
429
430
431
432
433
434 public void setLalign(String lalign) {
435 this.lalign = lalign;
436 }
437
438
439
440
441
442
443
444
445
446 public String getLclass() {
447 return lclass;
448 }
449
450
451
452
453
454
455
456
457
458 public void setLclass(String lclass) {
459 this.lclass = lclass;
460 }
461
462
463
464
465
466
467
468
469
470 public String getLcolspan() {
471 return lcolspan;
472 }
473
474
475
476
477
478
479
480
481
482 public void setLcolspan(String lcolspan) {
483 this.lcolspan = lcolspan;
484 }
485
486
487
488
489
490
491
492
493
494 public String getLname() {
495 return lname;
496 }
497
498
499
500
501
502
503
504
505
506 public void setLname(String lname) {
507 this.lname = lname;
508 }
509
510
511
512
513
514
515
516
517
518 public String getLrowspan() {
519 return lrowspan;
520 }
521
522
523
524
525
526
527
528
529
530 public void setLrowspan(String lrowspan) {
531 this.lrowspan = lrowspan;
532 }
533
534
535
536
537
538
539
540
541
542 public String getIwidth() {
543 return iwidth;
544 }
545
546
547
548
549
550
551
552
553
554 public void setIwidth(String iwidth) {
555 this.iwidth = iwidth;
556 }
557
558
559
560
561
562
563
564
565
566 public String getLwidth() {
567 return lwidth;
568 }
569
570
571
572
573
574
575
576
577
578 public void setLwidth(String lwidth) {
579 this.lwidth = lwidth;
580 }
581 }