1 /*
2 * Criado em 08/04/2004
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 * Classe para geração de Combo para Referência, utilizada no Relatório de Acompanhamento.<br>
23 * Exemplo de Utilização:<br>
24 * <combo:ComboTag <r>
25 * nome="referencia"<br>
26 * acompReferenciaItem="<%=acompReferenciaItem%>"/><br>
27 *
28 * @author evandro
29 */
30 public class ComboReferenciaTag implements Tag {
31
32 /**
33 * Nome da combo. Obrigatório.<br>
34 *
35 */
36 private String nome;
37
38 /**
39 * Objeto de onde se pega o item que monta a lista de valores a partir dele
40 * e também o valor que ficará selecionado na combo.<br>
41 */
42 private AcompReferenciaItemAri acompReferenciaItem;
43
44 /**
45 * Scripts da combo.
46 */
47 private String scripts;
48
49 /**
50 * Style da combo.
51 */
52 private String style;
53
54 /**
55 * Seta o estado da combo como disabled
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 * Inicializa a montagem da tag para ser adicionada na tela de HTML.<br>
70 *
71 * @author N/C
72 * @since N/C
73 * @version N/C
74 * @return int
75 * @throws JspException
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 /** Cria uma instância do objeto * */
85 //Object obj = Class.forName(getObjeto()).newInstance();
86 //Dao dao = new Dao();
87 //Session session = dao.getSession();
88
89 /** Constroi a combo * */
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 //Montar as opções a partir do item
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 * Atribui valor especificado para PageContext page.<br>
139 *
140 * @author N/C
141 * @since N/C
142 * @version N/C
143 * @param PageContext arg0
144 */
145 public void setPageContext(PageContext arg0) {
146 this.page = arg0;
147 }
148
149 /**
150 *
151 *
152 * @author N/C
153 * @since N/C
154 * @version N/C
155 * @param Tag arg0
156 */
157 public void setParent(Tag arg0) {
158 }
159
160 /**
161 * Retorna null.<br>
162 *
163 * @author N/C
164 * @since N/C
165 * @version N/C
166 * @return Tag
167 */
168 public Tag getParent() {
169 return null;
170 }
171
172 /**
173 * Encerra Tag.<br>
174 *
175 * @author N/C
176 * @since N/C
177 * @version N/C
178 * @return int
179 * @throws JspException
180 */
181 public int doEndTag() throws JspException {
182 return Tag.EVAL_PAGE;
183 }
184
185 /**
186 * @author N/C
187 * @since N/C
188 * @version N/C
189 */
190 public void release() {
191 //this.selected = null;
192 }
193
194
195 /**
196 * Retorna PageContext page.<br>
197 *
198 * @author N/C
199 * @since N/C
200 * @version N/C
201 * @return PageContext - (Returns the page)
202 */
203 public PageContext getPage() {
204 return page;
205 }
206
207 /**
208 * Atribui valor especificado para PageContext page.<br>
209 *
210 * @author N/C
211 * @since N/C
212 * @version N/C
213 * @param PageContext page - (The page to set)
214 */
215 public void setPage(PageContext page) {
216 this.page = page;
217 }
218
219
220 /**
221 * Retorna String nome.<br>
222 *
223 * @author N/C
224 * @since N/C
225 * @version N/C
226 * @return String - (Returns the nome)
227 */
228 public String getNome() {
229 return nome;
230 }
231
232 /**
233 * Atribui valor especificado para String nome.<br>
234 *
235 * @author N/C
236 * @since N/C
237 * @version N/C
238 * @param String nome - (The nome to set)
239 */
240 public void setNome(String nome) {
241 this.nome = nome;
242 }
243
244 /**
245 * Retorna AcompReferenciaItemAri acompReferenciaItem.<br>
246 *
247 * @author N/C
248 * @since N/C
249 * @version N/C
250 * @return AcompReferenciaItemAri - (Returns the acompReferenciaItem)
251 */
252 public AcompReferenciaItemAri getAcompReferenciaItem() {
253 return acompReferenciaItem;
254 }
255
256 /**
257 * Atribui valor especificado para AcompReferenciaItemAri acompReferenciaItem.<br>
258 *
259 * @author N/C
260 * @since N/C
261 * @version N/C
262 * @param AcompReferenciaItemAri acompReferenciaItem - (The acompReferenciaItem to set)
263 */
264 public void setAcompReferenciaItem(AcompReferenciaItemAri acompReferenciaItem) {
265 this.acompReferenciaItem = acompReferenciaItem;
266 }
267
268 /**
269 * Retorna String scripts.<br>
270 *
271 * @author N/C
272 * @since N/C
273 * @version N/C
274 * @return String - (Returns the scripts)
275 */
276 public String getScripts() {
277 return scripts;
278 }
279
280 /**
281 * Atribui valor especificado para String scripts.<br>
282 *
283 * @author N/C
284 * @since N/C
285 * @version N/C
286 * @param String scripts - (The scripts to set)
287 */
288 public void setScripts(String scripts) {
289 this.scripts = scripts;
290 }
291
292 /**
293 * Retorna String style.<br>
294 *
295 * @author N/C
296 * @since N/C
297 * @version N/C
298 * @return String - (Returns the style)
299 */
300 public String getStyle() {
301 return style;
302 }
303 /**
304 * Atribui valor especificado para String style.<br>
305 *
306 * @author N/C
307 * @since N/C
308 * @version N/C
309 * @param String style - (The style to set)
310 */
311 public void setStyle(String style) {
312 this.style = style;
313 }
314 /**
315 * Retorna String status.<br>
316 *
317 * @author N/C
318 * @since N/C
319 * @version N/C
320 * @return String - (Returns the style)
321 */
322 public String getStatus() {
323 return status;
324 }
325 /**
326 * Atribui valor especificado para String status
327 *
328 * @author N/C
329 * @since N/C
330 * @version N/C
331 * @param String style - (The style to set)
332 */
333 public void setStatus(String status) {
334 this.status = status;
335 }
336 }