1 package ecar.taglib.combos;
2
3 import java.util.List;
4
5 import javax.servlet.jsp.JspException;
6 import javax.servlet.jsp.JspWriter;
7 import javax.servlet.jsp.PageContext;
8 import javax.servlet.jsp.tagext.Tag;
9
10 import ecar.dao.AreaDao;
11 import ecar.pojo.AreaAre;
12
13
14
15
16 public class AreaTag implements Tag {
17
18 private String selected = "";
19 private PageContext page = null;
20 private AreaDao areaDao = new AreaDao(null);
21 private AreaAre area = new AreaAre();
22
23
24
25
26
27
28
29
30 public AreaTag() {
31 super();
32 }
33
34
35
36
37
38
39
40
41
42 public void setPageContext(PageContext arg0) {
43 this.page = arg0;
44 }
45
46
47
48
49
50
51
52 public void setParent(Tag arg0) {
53 }
54
55
56
57
58
59
60
61
62
63 public Tag getParent() {
64 return null;
65 }
66
67
68
69
70
71
72
73
74
75
76 public int doStartTag() throws JspException {
77 JspWriter writer = this.page.getOut();
78
79 try {
80 List lista = areaDao.listar(AreaAre.class, new String[] {"nomeAre","asc"});
81 writer.println("<option value=\"\"" + (selected.equals("") ? " selected" : "") + "></option>");
82 if (lista != null) {
83 for (int ii = 0; ii < lista.size(); ii++) {
84 area = (AreaAre) lista.get(ii);
85 String codigo = area.getCodAre().toString();
86 writer.println("<option value=\"" + codigo + "\"" +
87 (selected.equalsIgnoreCase(codigo) ? " selected" : "") + ">" +
88 area.getNomeAre() + "</option>");
89 }
90 }
91 } catch (Exception e) {
92 org.apache.log4j.Logger.getLogger(this.getClass()).error(e);
93 }
94 return Tag.EVAL_BODY_INCLUDE;
95 }
96
97
98
99
100
101
102
103
104
105
106 public int doEndTag() throws JspException {
107 return Tag.EVAL_PAGE;
108 }
109
110
111
112
113
114
115
116
117 public void release() {
118 this.selected = null;
119 }
120
121
122
123
124
125
126
127
128
129 public String getSelected() {
130 return selected;
131 }
132
133
134
135
136
137
138
139
140
141 public void setSelected(String string) {
142 selected = string;
143 }
144
145 }