1 /*
2 * Criado em 14/01/2005
3 *
4 */
5 package ecar.taglib.util;
6
7 import java.io.IOException;
8
9 import javax.servlet.jsp.JspException;
10 import javax.servlet.jsp.JspWriter;
11 import javax.servlet.jsp.PageContext;
12 import javax.servlet.jsp.tagext.Tag;
13
14 import org.apache.log4j.Logger;
15
16 /**
17 * Taglib para Criação de Combo com Opções SIM e NÃO.
18 * @author felipev
19 */
20 public class ComboSimNaoTag implements Tag{
21
22 String nome;
23 String valorSelecionado;
24 String opcaoBranco;
25 String scripts;
26
27 private PageContext page = null;
28
29 /**
30 * Inicializa a montagem da tag para ser adicionada na tela de HTML.<br>
31 *
32 * @author N/C
33 * @since N/C
34 * @version N/C
35 * @return int
36 * @throws JspException
37 */
38 public int doStartTag() throws JspException {
39 JspWriter writer = this.page.getOut();
40 StringBuffer s = new StringBuffer();
41 try{
42 s.append("<select name=\"").append(getNome()).append("\"").append(scripts).append(">");
43 if(opcaoBranco != null)
44 s.append("<option value=\"\">").append(getOpcaoBranco()).append("</option>");
45 s.append("<option value=\"S\"");
46 if("S".equals(getValorSelecionado()))
47 s.append(" selected ");
48 s.append(">Sim</option>");
49 s.append("<option value=\"N\"");
50 if("N".equals(getValorSelecionado()))
51 s.append(" selected ");
52 s.append(">Não</option>");
53 s.append("</select>");
54 writer.print(s);
55 } catch (Exception e) {
56 Logger logger = Logger.getLogger(this.getClass());
57 logger.error(e);
58 try{
59 writer.print("Erro na geração da Combo: " + e.getMessage());
60 logger.error(e);
61 }catch(IOException ioE){
62 logger.error(ioE);
63 }
64 }
65 return Tag.EVAL_BODY_INCLUDE;
66 }
67
68 /**
69 * @author N/C
70 * @since N/C
71 * @version N/C
72 * @param Tag arg0
73 */
74 public void setParent(Tag arg0) {
75 }
76
77 /**
78 * Retorna Tag null.<br>
79 *
80 * @author N/C
81 * @since N/C
82 * @version N/C
83 * @return Tag
84 */
85 public Tag getParent() {
86 return null;
87 }
88
89 /**
90 * Encerra Tag.<br>
91 *
92 * @author N/C
93 * @since N/C
94 * @version N/C
95 * @return int
96 * @throws JspException
97 */
98 public int doEndTag() throws JspException {
99 return Tag.EVAL_PAGE;
100 }
101
102 /**
103 *
104 *
105 * @author N/C
106 * @since N/C
107 * @version N/C
108 */
109 public void release() {
110 //this.selected = null;
111 }
112
113 /**
114 * Retorna PageContext page.<br>
115 *
116 * @author N/C
117 * @since N/C
118 * @version N/C
119 * @return PageContext - (Returns the page)
120 */
121 public PageContext getPage() {
122 return page;
123 }
124
125 /**
126 * Atribui valor especificado para PageContext page.<br>
127 *
128 * @author N/C
129 * @since N/C
130 * @version N/C
131 * @param PageContext page - (The page to set)
132 */
133 public void setPage(PageContext page) {
134 this.page = page;
135 }
136
137 /**
138 * Retorna String nome
139 *
140 * @author N/C
141 * @since N/C
142 * @version N/C
143 * @return String - (Returns the nome)
144 */
145 public String getNome() {
146 return nome;
147 }
148
149 /**
150 * Atribui valor especificado para String nome.<br>
151 *
152 * @author N/C
153 * @since N/C
154 * @version N/C
155 * @param String nome - (The nome to set)
156 */
157 public void setNome(String nome) {
158 this.nome = nome;
159 }
160
161 /**
162 * Retorna String opcaoBranco.<br>
163 *
164 * @author N/C
165 * @since N/C
166 * @version N/C
167 * @return String - (Returns the opcaoBranco)
168 */
169 public String getOpcaoBranco() {
170 return opcaoBranco;
171 }
172
173 /**
174 * Atribui valor especificado para String opcaoBranco.<br>
175 *
176 * @author N/C
177 * @since N/C
178 * @version N/C
179 * @param String opcaoBranco - (The opcaoBranco to set)
180 */
181 public void setOpcaoBranco(String opcaoBranco) {
182 this.opcaoBranco = opcaoBranco;
183 }
184
185 /**
186 * Retorna String valorSelecionado.<br>
187 *
188 * @author N/C
189 * @since N/C
190 * @version N/C
191 * @return String - (Returns the valorSelecionado)
192 */
193 public String getValorSelecionado() {
194 return valorSelecionado;
195 }
196
197 /**
198 * Atribui valor especificado para String valorSelecionado.<br>
199 *
200 * @author N/C
201 * @since N/C
202 * @version N/C
203 * @param String valorSelecionado - (The valorSelecionado to set)
204 */
205 public void setValorSelecionado(String valorSelecionado) {
206 this.valorSelecionado = valorSelecionado;
207 }
208
209 /**
210 * Atribui valor especificado para PageContext page.<br>
211 *
212 * @author N/C
213 * @since N/C
214 * @version N/C
215 * @param PageContext arg0
216 */
217 public void setPageContext(PageContext arg0) {
218 this.page = arg0;
219 }
220
221 /**
222 * Retorna String scripts.<br>
223 *
224 * @author N/C
225 * @since N/C
226 * @version N/C
227 * @return String - (Returns the scripts)
228 */
229 public String getScripts() {
230 return scripts;
231 }
232
233 /**
234 * Atribui valor especificado para String scripts.<br>
235 *
236 * @author N/C
237 * @since N/C
238 * @version N/C
239 * @param String scripts - (The scripts to set)
240 */
241 public void setScripts(String scripts) {
242 this.scripts = scripts;
243 }
244
245 }