1
2
3
4
5 package ecar.taglib.combos;
6
7 import java.io.IOException;
8 import java.util.Iterator;
9 import java.util.List;
10
11 import javax.servlet.jsp.JspException;
12 import javax.servlet.jsp.JspWriter;
13 import javax.servlet.jsp.PageContext;
14 import javax.servlet.jsp.tagext.Tag;
15
16 import org.apache.log4j.Logger;
17
18 import ecar.dao.AcompReferenciaItemDao;
19 import ecar.pojo.AcompReferenciaItemAri;
20
21
22
23
24
25
26
27
28
29
30 public class ComboReferenciaTag implements Tag {
31
32
33
34
35
36 private String nome;
37
38
39
40
41
42 private AcompReferenciaItemAri acompReferenciaItem;
43
44
45
46
47 private String scripts;
48
49
50
51
52 private String style;
53
54
55
56
57 private String status;
58
59 private PageContext page = null;
60
61 private Logger logger = null;
62
63 public ComboReferenciaTag() {
64 super();
65 this.logger = Logger.getLogger(this.getClass());
66 }
67
68
69
70
71
72
73
74
75
76
77 public int doStartTag() throws JspException {
78 JspWriter writer = this.page.getOut();
79 StringBuffer s = new StringBuffer();
80
81 AcompReferenciaItemDao acompReferenciaItemDao = new AcompReferenciaItemDao(null);
82
83 try {
84
85
86
87
88
89
90 s.append("<select name=\"").append(nome).append("\" ");
91 s.append(" id=\"").append(nome).append("\" ");
92
93 if(scripts != null && !"".equals(scripts))
94 s.append( scripts );
95
96 if (style != null && !"".equals(style))
97 s.append(" style=\"").append(style).append("\"");
98
99 if (status != null && !"".equals(status))
100 s.append( status );
101
102 s.append(">");
103
104
105 List lista = acompReferenciaItemDao.getReferenciaByItem(acompReferenciaItem);
106 Iterator it = lista.iterator();
107 AcompReferenciaItemAri acompRefItemLista;
108
109 String sel = "";
110
111 while(it.hasNext()){
112 acompRefItemLista = (AcompReferenciaItemAri) it.next();
113 sel = "";
114
115 if(acompRefItemLista.getCodAri() == acompReferenciaItem.getCodAri())
116 sel = "selected";
117
118 s.append("<option ").append(sel).append(" value=\"").append(acompRefItemLista.getCodAri()).append("\">");
119 s.append(acompRefItemLista.getAcompReferenciaAref().getNomeAref()).append("</option>");
120 }
121
122 s.append("</select>");
123 writer.print(s.toString());
124 } catch (Exception e) {
125 this.logger.error(e);
126 try {
127 writer.print("Erro na geração da Combo: " + e.getMessage());
128 this.logger.error(e);
129 } catch (IOException ioE) {
130 this.logger.error(ioE);
131 }
132
133 }
134 return Tag.EVAL_BODY_INCLUDE;
135 }
136
137
138
139
140
141
142
143
144
145 public void setPageContext(PageContext arg0) {
146 this.page = arg0;
147 }
148
149
150
151
152
153
154
155
156
157 public void setParent(Tag arg0) {
158 }
159
160
161
162
163
164
165
166
167
168 public Tag getParent() {
169 return null;
170 }
171
172
173
174
175
176
177
178
179
180
181 public int doEndTag() throws JspException {
182 return Tag.EVAL_PAGE;
183 }
184
185
186
187
188
189
190 public void release() {
191
192 }
193
194
195
196
197
198
199
200
201
202
203 public PageContext getPage() {
204 return page;
205 }
206
207
208
209
210
211
212
213
214
215 public void setPage(PageContext page) {
216 this.page = page;
217 }
218
219
220
221
222
223
224
225
226
227
228 public String getNome() {
229 return nome;
230 }
231
232
233
234
235
236
237
238
239
240 public void setNome(String nome) {
241 this.nome = nome;
242 }
243
244
245
246
247
248
249
250
251
252 public AcompReferenciaItemAri getAcompReferenciaItem() {
253 return acompReferenciaItem;
254 }
255
256
257
258
259
260
261
262
263
264 public void setAcompReferenciaItem(AcompReferenciaItemAri acompReferenciaItem) {
265 this.acompReferenciaItem = acompReferenciaItem;
266 }
267
268
269
270
271
272
273
274
275
276 public String getScripts() {
277 return scripts;
278 }
279
280
281
282
283
284
285
286
287
288 public void setScripts(String scripts) {
289 this.scripts = scripts;
290 }
291
292
293
294
295
296
297
298
299
300 public String getStyle() {
301 return style;
302 }
303
304
305
306
307
308
309
310
311 public void setStyle(String style) {
312 this.style = style;
313 }
314
315
316
317
318
319
320
321
322 public String getStatus() {
323 return status;
324 }
325
326
327
328
329
330
331
332
333 public void setStatus(String status) {
334 this.status = status;
335 }
336 }