1 16 package org.ajaxtags.tags; 17 18 import java.io.IOException ; 19 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.JspWriter ; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 24 import org.apache.commons.lang.StringUtils; 25 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 26 27 33 public class AjaxTabPanelTag extends TagSupport { 34 35 private String var; 36 37 private String attachTo; 38 39 private String panelStyleId; 40 41 private String contentStyleId; 42 43 private String panelStyleClass; 44 45 private String contentStyleClass; 46 47 private String currentStyleClass; 48 49 private String defaultTabBaseUrl; 50 51 private String defaultTabParameters = ""; 52 53 private String preFunction; 54 55 private String postFunction; 56 57 private String errorFunction; 58 59 private String parser; 60 61 public String getContentStyleId() { 62 return contentStyleId; 63 } 64 65 public void setContentStyleId(String contentStyleId) { 66 this.contentStyleId = contentStyleId; 67 } 68 69 public String getDefaultTabParameters() { 70 return defaultTabParameters; 71 } 72 73 public void setDefaultTabParameters(String defaultTabParameters) { 74 this.defaultTabParameters = defaultTabParameters; 75 } 76 77 public String getDefaultTabBaseUrl() { 78 return defaultTabBaseUrl; 79 } 80 81 public void setDefaultTabBaseUrl(String defaultTab) { 82 this.defaultTabBaseUrl = defaultTab; 83 } 84 85 public String getErrorFunction() { 86 return errorFunction; 87 } 88 89 public void setErrorFunction(String errorFunction) { 90 this.errorFunction = errorFunction; 91 } 92 93 public String getPanelStyleId() { 94 return panelStyleId; 95 } 96 97 public void setPanelStyleId(String panelStyleId) { 98 this.panelStyleId = panelStyleId; 99 } 100 101 public String getParser() { 102 return parser; 103 } 104 105 public void setParser(String parser) { 106 this.parser = parser; 107 } 108 109 public String getPreFunction() { 110 return preFunction; 111 } 112 113 public void setPreFunction(String preFunction) { 114 this.preFunction = preFunction; 115 } 116 117 public String getPostFunction() { 118 return postFunction; 119 } 120 121 public void setPostFunction(String postFunction) { 122 this.postFunction = postFunction; 123 } 124 125 public String getVar() { 126 return var; 127 } 128 129 public void setVar(String var) { 130 this.var = var; 131 } 132 133 public String getAttachTo() { 134 return attachTo; 135 } 136 137 public void setAttachTo(String attachTo) { 138 this.attachTo = attachTo; 139 } 140 141 public String getContentStyleClass() { 142 return contentStyleClass; 143 } 144 145 public void setContentStyleClass(String contentStyleClass) { 146 this.contentStyleClass = contentStyleClass; 147 } 148 149 public String getCurrentStyleClass() { 150 return currentStyleClass; 151 } 152 153 public void setCurrentStyleClass(String currentStyleClass) { 154 this.currentStyleClass = currentStyleClass; 155 } 156 157 public String getPanelStyleClass() { 158 return panelStyleClass; 159 } 160 161 public void setPanelStyleClass(String panelStyleClass) { 162 this.panelStyleClass = panelStyleClass; 163 } 164 165 @Override 166 public int doStartTag() throws JspException { 167 this.panelStyleId = (String ) ExpressionEvaluatorManager.evaluate( 169 "panelStyleId", this.panelStyleId, String .class, this, 170 super.pageContext); 171 this.contentStyleId = (String ) ExpressionEvaluatorManager.evaluate( 172 "contentStyleId", this.contentStyleId, String .class, this, 173 super.pageContext); 174 this.currentStyleClass = (String ) ExpressionEvaluatorManager.evaluate( 175 "currentStyleClass", this.currentStyleClass, String .class, 176 this, super.pageContext); 177 178 if (this.var != null) { 180 this.var = (String ) ExpressionEvaluatorManager.evaluate("var", 181 this.var, String .class, this, super.pageContext); 182 } 183 if (this.attachTo != null) { 184 this.attachTo = (String ) ExpressionEvaluatorManager.evaluate( 185 "attachTo", this.attachTo, String .class, this, 186 super.pageContext); 187 } 188 if (this.preFunction != null) { 189 this.preFunction = (String ) ExpressionEvaluatorManager.evaluate( 190 "preFunction", this.preFunction, String .class, this, 191 super.pageContext); 192 } 193 if (this.postFunction != null) { 194 this.postFunction = (String ) ExpressionEvaluatorManager.evaluate( 195 "postFunction", this.postFunction, String .class, this, 196 super.pageContext); 197 } 198 if (this.errorFunction != null) { 199 this.errorFunction = (String ) ExpressionEvaluatorManager.evaluate( 200 "errorFunction", this.errorFunction, String .class, this, 201 super.pageContext); 202 } 203 204 StringBuffer script = new StringBuffer (); 205 script.append("<div id=\""); 206 script.append(this.panelStyleId); 207 script.append("\" class=\""); 208 script.append(this.panelStyleClass); 209 script.append("\">\n<ul>"); 210 JspWriter writer = pageContext.getOut(); 211 try { 212 writer.println(script); 213 } catch (IOException e) { 214 throw new JspException (e.getMessage()); 215 } 216 return EVAL_BODY_INCLUDE; 217 } 218 219 @Override 220 public int doEndTag() throws JspException { 221 OptionsBuilder options = new OptionsBuilder(); 222 options.add("source", "elem", false); 223 options.add("target", this.contentStyleId, true); 224 options.add("panelId", this.panelStyleId, true); 225 options.add("currentStyleClass", "currentClass", false); 226 options.add("parameters", "params", false); 227 if (this.preFunction != null) 228 options.add("preFunction", this.preFunction, false); 229 if (this.postFunction != null) 230 options.add("postFunction", this.postFunction, false); 231 if (this.errorFunction != null) 232 options.add("errorFunction", this.errorFunction, false); 233 if (this.parser != null) 234 options.add("parser", this.parser, false); 235 236 StringBuffer script = new StringBuffer (); 237 script.append("</ul>\n</div>\n<div id=\""); 238 script.append(this.contentStyleId); 239 script.append("\" class=\""); 240 script.append(this.contentStyleClass); 241 script.append("\"></div>\n"); 242 script.append("<script type=\"text/javascript\">\n"); 243 script.append("window.executeAjaxTab_"); 244 script.append(panelStyleId); 245 script.append(" = function(elem, currentClass, url, params) {\n"); 246 247 if (StringUtils.isNotEmpty(this.attachTo)) { 248 script.append(this.attachTo).append("."); 249 if (StringUtils.isNotEmpty(this.var)) { 250 script.append(this.var); 251 } else { 252 script.append("aj_").append(this.panelStyleId); 253 } 254 } else if (StringUtils.isNotEmpty(this.var)) { 255 script.append("var ").append(this.var); 256 } else { 257 script.append("var aj_").append(this.panelStyleId); 258 } 259 260 script.append(" = new AjaxJspTag.TabPanel(url, {\n").append( 261 options.toString()).append("});\n").append("}\n\n").append( 262 "addOnLoadEvent(function() {window.executeAjaxTab_").append( 263 panelStyleId).append("(null, '").append(this.currentStyleClass) 264 .append("', '").append(this.getDefaultTabBaseUrl()).append( 265 "', '").append(this.getDefaultTabParameters()).append( 266 "');});\n").append("</script>\n\n"); 267 JspWriter writer = pageContext.getOut(); 268 try { 269 writer.println(script); 270 } catch (IOException e) { 271 throw new JspException (e.getMessage()); 272 } 273 return EVAL_PAGE; 274 } 275 276 @Override 277 public void release() { 278 this.var = null; 279 this.attachTo = null; 280 this.panelStyleId = null; 281 this.contentStyleId = null; 282 this.panelStyleClass = null; 283 this.contentStyleClass = null; 284 this.currentStyleClass = null; 285 this.defaultTabBaseUrl = null; 286 this.defaultTabParameters = null; 287 this.preFunction = null; 288 this.postFunction = null; 289 this.errorFunction = null; 290 this.parser = null; 291 super.release(); 292 } 293 294 } 295
| Popular Tags
|