1 16 17 18 package org.apache.webapp.admin; 19 20 21 import java.io.IOException ; 22 import java.net.URLEncoder ; 23 import java.util.ArrayList ; 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.JspWriter ; 26 import javax.servlet.jsp.PageContext ; 27 import javax.servlet.jsp.tagext.BodyTagSupport ; 28 29 30 48 49 public class ActionsTag extends BodyTagSupport { 50 51 52 54 55 60 protected static final String FUNCTION_TAG = 61 "org.apache.webapp.admin.ActionsTag.FUNCTION_TAG"; 62 63 64 66 67 70 protected ArrayList labels = new ArrayList (); 71 72 73 76 protected ArrayList selecteds = new ArrayList (); 77 78 81 protected ArrayList disableds = new ArrayList (); 82 83 86 protected ArrayList urls = new ArrayList (); 87 88 89 91 92 95 protected int size = 1; 96 97 public int getSize() { 98 return (this.size); 99 } 100 101 public void setSize(int size) { 102 this.size = size; 103 } 104 105 106 110 protected String style = null; 111 112 public String getStyle() { 113 return (this.style); 114 } 115 116 public void setStyle(String style) { 117 this.style = style; 118 } 119 120 121 124 protected String label = null; 125 126 public String getLabel() { 127 return (this.label); 128 } 129 130 public void setLabel(String label) { 131 this.label = label; 132 } 133 134 135 137 public int doStartTag() throws JspException { 138 139 this.labels.clear(); 140 this.selecteds.clear(); 141 this.urls.clear(); 142 143 return (EVAL_BODY_TAG); 144 145 } 146 147 148 153 public int doEndTag() throws JspException { 154 155 JspWriter out = pageContext.getOut(); 156 157 try { 158 159 if (pageContext.getAttribute(FUNCTION_TAG) == null) { 161 out.println(); 162 out.println("<script language=\"JavaScript\">"); 163 out.println("<!--"); 164 out.println("function IA_jumpMenu(targ,selObj) {"); 165 out.println(" dest = selObj.options[selObj.selectedIndex].value;"); 166 out.println(" if (dest.length > 0) {"); 167 out.println(" eval(targ+\".location='\"+dest+\"'\");"); 168 out.println(" }"); 169 out.println("}"); 170 out.println("//-->"); 171 out.println("</script>"); 172 out.println(); 173 pageContext.setAttribute(FUNCTION_TAG, Boolean.TRUE); 174 } 175 176 178 if (label != null) { 179 out.print("<label for=\"labelId\">"); 180 out.print(label); 181 out.println("</label>"); 182 } 183 out.println(); 185 out.print("<select"); 186 if (size > 1) { 187 out.print(" size=\""); 188 out.print(size); 189 out.print("\""); 190 } 191 if (style != null) { 192 out.print(" class=\""); 193 out.print(style); 194 out.print("\""); 195 } 196 if (label != null) { 197 out.print(" id=\""); 198 out.print("labelId"); 199 out.print("\""); 200 } 201 202 out.print(" onchange=\"IA_jumpMenu('self',this)\""); 203 out.println(">"); 204 205 int n = labels.size(); 207 for (int i = 0; i < n; i++) { 208 String label = (String ) labels.get(i); 209 boolean selected = ((Boolean ) selecteds.get(i)).booleanValue(); 210 boolean disabled = ((Boolean ) disableds.get(i)).booleanValue(); 211 String url = (String ) urls.get(i); 212 out.print("<option"); 213 if (selected) 214 out.print(" selected=\"selected\""); 215 if (disabled) 216 out.print(" disabled=\"true\""); 217 out.print(" value=\""); 218 if (url != null) 219 out.print(url); 220 out.print("\""); 221 out.print(">"); 222 if (label != null) 223 out.print(label); 224 out.println("</option>"); 225 } 226 227 out.println("</select>"); 229 out.println(); 230 231 } catch (IOException e) { 232 throw new JspException (e); 233 } 234 235 return (EVAL_PAGE); 236 237 } 238 239 240 243 public void release() { 244 245 this.labels.clear(); 246 this.selecteds.clear(); 247 this.urls.clear(); 248 249 this.size = 1; 250 this.style = null; 251 252 } 253 254 255 257 258 266 void addAction(String label, boolean selected, boolean disabled, String url) { 267 268 labels.add(label); 269 selecteds.add(new Boolean (selected)); 270 disableds.add(new Boolean (disabled)); 271 urls.add(url); 272 273 } 274 275 276 278 279 } 280 | Popular Tags |