View Javadoc

1   /*
2    * Created on 17/09/2004
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   * @author garten
16   * 
17   * TagLib para tratar campos input
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  	// constantes da sintaxe do html
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  	// opcoes do input
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  	// opcoes do td do input
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  	// opcoes do label
64  	private String lname = "";
65  	// opcoes do td do label
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  	//private String checked;
73  	//private String disabled;
74  	//private String readonly;
75  	
76  	/**
77  	 * Inicializa a montagem da tag para ser adicionada na tela de HTML.<br>
78  	 * 
79  	 * @author N/C
80  	 * @since N/C
81  	 * @version N/C
82  	 * @return int
83  	 * @throws JspException
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  		// opcoes do input
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 		//opcoes do td do input
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 		// opcoes do td do label
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 	 * Encerra Tag.<br>
163 	 * 
164 	 * @author N/C
165 	 * @since N/C
166 	 * @version N/C
167 	 * @return int
168 	 * @throws JspException
169 	 */
170 	public int doEndTag() throws JspException {
171 		return Tag.EVAL_PAGE;
172 	}
173 	
174 	/**
175 	 * Retorna String ialign
176 	 * 
177 	 * @author N/C
178 	 * @since N/C
179 	 * @version N/C
180 	 * @return String
181 	 */
182 	public String getIalign() {
183 		return ialign;
184 	}
185 	
186 	/**
187 	 * Atribui valor especificado para String ialign.<br>
188 	 * 
189 	 * @author N/C
190 	 * @since N/C
191 	 * @version N/C
192 	 * @param String ialign
193 	 */
194 	public void setIalign(String ialign) {
195 		this.ialign = ialign;
196 	}
197 	
198 	/**
199 	 * Retorna String iclass.<br>
200 	 * 
201 	 * @author N/C
202 	 * @since N/C
203 	 * @version N/C
204 	 * @return String
205 	 */
206 	public String getIclass() {
207 		return iclass;
208 	}
209 	
210 	/**
211 	 * Atribui valor especificado para String iclass.<br>
212 	 * 
213 	 * @author N/C
214 	 * @since N/C
215 	 * @version N/C
216 	 * @param String iclass
217 	 */
218 	public void setIclass(String iclass) {
219 		this.iclass = iclass;
220 	}
221 	
222 	/**
223 	 * Retorna String icolspan.<br>
224 	 * 
225 	 * @author N/C
226 	 * @since N/C
227 	 * @version N/C
228 	 * @return String
229 	 */
230 	public String getIcolspan() {
231 		return icolspan;
232 	}
233 	
234 	/**
235 	 * Atribui valor especificado para String icolspan.<br>
236 	 * 
237 	 * @author N/C
238 	 * @since N/C
239 	 * @version N/C
240 	 * @param String icolspan
241 	 */
242 	public void setIcolspan(String icolspan) {
243 		this.icolspan = icolspan;
244 	}
245 	
246 	/**
247 	 * Retorna String iextra.<br>
248 	 * 
249 	 * @author N/C
250 	 * @since N/C
251 	 * @version N/C
252 	 * @return String
253 	 */
254 	public String getIextra() {
255 		return iextra;
256 	}
257 	
258 	/**
259 	 * Atribui valor especificado para String iextra.<br>
260 	 * 
261 	 * @author N/C
262 	 * @since N/C
263 	 * @version N/C
264 	 * @param String iextra
265 	 */
266 	public void setIextra(String iextra) {
267 		this.iextra = iextra;
268 	}
269 	
270 	/**
271 	 * Retorna String imaxlength.<br>
272 	 * 
273 	 * @author N/C
274 	 * @since N/C
275 	 * @version N/C
276 	 * @return String
277 	 */
278 	public String getImaxlength() {
279 		return imaxlength;
280 	}
281 	
282 	/**
283 	 * Atribui valor especificado para String imaxlength.<br>
284 	 * 
285 	 * @author N/C
286 	 * @since N/C
287 	 * @version N/C
288 	 * @param String imaxlength
289 	 */
290 	public void setImaxlength(String imaxlength) {
291 		this.imaxlength = imaxlength;
292 	}
293 	
294 	/**
295 	 * Retorna String iname.<br>
296 	 * 
297 	 * @author N/C
298 	 * @since N/C
299 	 * @version N/C
300 	 * @return String
301 	 */
302 	public String getIname() {
303 		return iname;
304 	}
305 	
306 	/**
307 	 * Atribui valor especificado para String iname.<br>
308 	 * 
309 	 * @author N/C
310 	 * @since N/C
311 	 * @version N/C
312 	 * @param String iname
313 	 */
314 	public void setIname(String iname) {
315 		this.iname = iname;
316 	}
317 	
318 	/**
319 	 * Retorna String irowspan.<br>
320 	 * 
321 	 * @author N/C
322 	 * @since N/C
323 	 * @version N/C
324 	 * @return String
325 	 */
326 	public String getIrowspan() {
327 		return irowspan;
328 	}
329 	
330 	/**
331 	 * Atribui valor especificado para String irowspan.<br>
332 	 * 
333 	 * @author N/C
334 	 * @since N/C
335 	 * @version N/C
336 	 * @param String irowspan
337 	 */
338 	public void setIrowspan(String irowspan) {
339 		this.irowspan = irowspan;
340 	}
341 	
342 	/**
343 	 * Retorna String isize.<br>
344 	 * 
345 	 * @author N/C
346 	 * @since N/C
347 	 * @version N/C
348 	 * @return String
349 	 */
350 	public String getIsize() {
351 		return isize;
352 	}
353 	
354 	/**
355 	 * Atribui valor especificado para String isize.<br>
356 	 * 
357 	 * @author N/C
358 	 * @since N/C
359 	 * @version N/C
360 	 * @param String isize
361 	 */
362 	public void setIsize(String isize) {
363 		this.isize = isize;
364 	}
365 	
366 	/**
367 	 * Retorna String itype.<br>
368 	 * 
369 	 * @author N/C
370 	 * @since N/C
371 	 * @version N/C
372 	 * @return String
373 	 */
374 	public String getItype() {
375 		return itype;
376 	}
377 	
378 	/**
379 	 * Atribui valor especificado para String itype.<br>
380 	 * 
381 	 * @author N/C
382 	 * @since N/C
383 	 * @version N/C
384 	 * @param String itype
385 	 */
386 	public void setItype(String itype) {
387 		this.itype = itype;
388 	}
389 	
390 	/**
391 	 * Retorna String ivalue.<br>
392 	 * 
393 	 * @author N/C
394 	 * @since N/C
395 	 * @version N/C
396 	 * @return String
397 	 */
398 	public String getIvalue() {
399 		return ivalue;
400 	}
401 	
402 	/**
403 	 * Atribui valor especificado para String ivalue.<br>
404 	 * 
405 	 * @author N/C
406 	 * @since N/C
407 	 * @version N/C
408 	 * @param String ivalue
409 	 */
410 	public void setIvalue(String ivalue) {
411 		this.ivalue = ivalue;
412 	}
413 	
414 	/**
415 	 * Retorna String lalign.<br>
416 	 * 
417 	 * @author N/C
418 	 * @since N/C
419 	 * @version N/C
420 	 * @return String
421 	 */
422 	public String getLalign() {
423 		return lalign;
424 	}
425 	
426 	/**
427 	 * Atribui valor especificado para String lalign.<br>
428 	 * 
429 	 * @author N/C
430 	 * @since N/C
431 	 * @version N/C
432 	 * @param String lalign
433 	 */
434 	public void setLalign(String lalign) {
435 		this.lalign = lalign;
436 	}
437 	
438 	/**
439 	 * Retorna String lclass.<br>
440 	 * 
441 	 * @author N/C
442 	 * @since N/C
443 	 * @version N/C
444 	 * @return String
445 	 */
446 	public String getLclass() {
447 		return lclass;
448 	}
449 	
450 	/**
451 	 * Atribui valor especificado para String lclass.<br>
452 	 * 
453 	 * @author N/C
454 	 * @since N/C
455 	 * @version N/C
456 	 * @param String lclass
457 	 */
458 	public void setLclass(String lclass) {
459 		this.lclass = lclass;
460 	}
461 	
462 	/**
463 	 * Retorna String lcolspan.<br>
464 	 * 
465 	 * @author N/C
466 	 * @since N/C
467 	 * @version N/C
468 	 * @return String
469 	 */
470 	public String getLcolspan() {
471 		return lcolspan;
472 	}
473 	
474 	/**
475 	 * Atribui valor especificado para String lcolspan.<br>
476 	 * 
477 	 * @author N/C
478 	 * @since N/C
479 	 * @version N/C
480 	 * @param lcolspan
481 	 */
482 	public void setLcolspan(String lcolspan) {
483 		this.lcolspan = lcolspan;
484 	}
485 	
486 	/**
487 	 * Retorna String lname.<br>
488 	 * 
489 	 * @author N/C
490 	 * @since N/C
491 	 * @version N/C
492 	 * @return String
493 	 */
494 	public String getLname() {
495 		return lname;
496 	}
497 	
498 	/**
499 	 * Atribui valor especificado para String lname.<br>
500 	 * 
501 	 * @author N/C
502 	 * @since N/C
503 	 * @version N/C
504 	 * @param lname
505 	 */
506 	public void setLname(String lname) {
507 		this.lname = lname;
508 	}
509 	
510 	/**
511 	 * Retorna String lrowspan.<br>
512 	 * 
513 	 * @author N/C
514 	 * @since N/C
515 	 * @version N/C
516 	 * @return String
517 	 */
518 	public String getLrowspan() {
519 		return lrowspan;
520 	}
521 	
522 	/**
523 	 * Atribui valor especificado para String lrowspan.<br>
524 	 * 
525 	 * @author N/C
526 	 * @since N/C
527 	 * @version N/C
528 	 * @param String lrowspan
529 	 */
530 	public void setLrowspan(String lrowspan) {
531 		this.lrowspan = lrowspan;
532 	}
533 	
534 	/**
535 	 * Retorna String iwidth.<br>
536 	 * 
537 	 * @author N/C
538 	 * @since N/C
539 	 * @version N/C
540 	 * @return String
541 	 */
542 	public String getIwidth() {
543 		return iwidth;
544 	}
545 	
546 	/**
547 	 * Atribui valor especificado para String iwidth.<br>
548 	 * 
549 	 * @author N/C
550 	 * @since N/C
551 	 * @version N/C
552 	 * @param String iwidth
553 	 */
554 	public void setIwidth(String iwidth) {
555 		this.iwidth = iwidth;
556 	}
557 	
558 	/**
559 	 * Retorna String lwidth.<br>
560 	 * 
561 	 * @author N/C
562 	 * @since N/C
563 	 * @version N/C
564 	 * @return String
565 	 */
566 	public String getLwidth() {
567 		return lwidth;
568 	}
569 	
570 	/**
571 	 * Atribui valor especificado para String lwidth.<br>
572 	 * 
573 	 * @author N/C
574 	 * @since N/C
575 	 * @version N/C
576 	 * @param String lwidth
577 	 */
578 	public void setLwidth(String lwidth) {
579 		this.lwidth = lwidth;
580 	}
581 }