View Javadoc

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   * @author rodrigo.hjort
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  	 * Construtor.<br>
25  	 * 
26  	 * @author N/C
27       * @since N/C
28       * @version N/C
29  	 */
30  	public AreaTag() {
31  		super();
32  	}
33  
34  	/**
35  	 * Atribui valor especificado para PageContext page.<br>
36  	 * 
37  	 * @author N/C
38       * @since N/C
39       * @version N/C
40       * @param PageContext arg0
41  	 */
42  	public void setPageContext(PageContext arg0) {
43  		this.page = arg0;
44  	}
45  
46  	/**
47  	 * @author N/C
48       * @since N/C
49       * @version N/C
50       * @param Tag arg0
51  	 */
52  	public void setParent(Tag arg0) {
53  	}
54  
55  	/**
56  	 * Retorna null.<br>
57  	 * 
58  	 * @author N/C
59       * @since N/C
60       * @version N/C
61       * @return Tag
62  	 */
63  	public Tag getParent() {
64  		return null;
65  	}
66  
67  	/**
68  	 * Inicializa a montagem da tag para ser adicionada na tela de HTML.<br>
69  	 * 
70  	 * @author N/C
71       * @since N/C
72       * @version N/C
73       * @return int
74       * @throws JspException
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  	 * Encerra Tag.<br>
99  	 * 
100 	 * @author N/C
101      * @since N/C
102      * @version N/C
103      * @return int
104      * @throws JspException
105 	 */
106 	public int doEndTag() throws JspException {
107 		return Tag.EVAL_PAGE;
108 	}
109 
110 	/**
111 	 * Atribui null para selected.<br>
112 	 * 
113 	 * @author N/C
114      * @since N/C
115      * @version N/C
116 	 */
117 	public void release() {
118 		this.selected = null;
119 	}
120 
121 	/**
122 	 * Retorna String selected.<br>
123 	 * 
124 	 * @author N/C
125      * @since N/C
126      * @version N/C
127 	 * @return String
128 	 */
129 	public String getSelected() {
130 		return selected;
131 	}
132 
133 	/**
134 	 * Atribui valor epsecificado para selected.<br>
135 	 * 
136 	 * @author N/C
137      * @since N/C
138      * @version N/C
139 	 * @param String string
140 	 */
141 	public void setSelected(String string) {
142 		selected = string;
143 	}
144 
145 }