1 16 package org.directwebremoting.proxy.dwr; 17 18 import java.util.Collection ; 19 import java.util.Map ; 20 21 import org.directwebremoting.ScriptBuffer; 22 import org.directwebremoting.ScriptSession; 23 import org.directwebremoting.proxy.ScriptProxy; 24 25 42 public class Util extends ScriptProxy 43 { 44 49 public Util() 50 { 51 super(); 52 } 53 54 58 public Util(ScriptSession scriptSession) 59 { 60 super(scriptSession); 61 } 62 63 67 public Util(Collection scriptSessions) 68 { 69 super(scriptSessions); 70 } 71 72 78 public void setValue(String elementId, String value) 79 { 80 setValue(elementId, value, false); 81 } 82 83 90 public void setValue(String elementId, String value, boolean escapeHtml) 91 { 92 String options = escapeHtml ? "{escapeHtml:true}" : "{escapeHtml:false}"; 93 addFunctionCall("dwr.util.setValue", elementId, value, options); 94 } 95 96 103 public void setValues(Map values, boolean escapeHtml) 104 { 105 String options = escapeHtml ? "{escapeHtml:true}" : "{escapeHtml:false}"; 106 addFunctionCall("dwr.util.setValue", values, options); 107 } 108 109 115 public void addOptions(String elementId, String [] array) 116 { 117 addFunctionCall("dwr.util.addOptions", elementId, array); 118 } 119 120 127 public void addOptions(String elementId, Collection array, String property) 128 { 129 addFunctionCall("dwr.util.addOptions", elementId, array, property); 130 } 131 132 140 public void addOptions(String elementId, Collection array, String valueProperty, String textProperty) 141 { 142 addFunctionCall("dwr.util.addOptions", elementId, array, valueProperty, textProperty); 143 } 144 145 150 public void removeAllOptions(String elementId) 151 { 152 addFunctionCall("dwr.util.removeAllOptions", elementId); 153 } 154 155 162 public void addRows(String elementId, String [][] data, String options) 163 { 164 if (data.length > 0) 165 { 166 StringBuffer functions = new StringBuffer (); 167 for (int i = 0; i < data[0].length; i++) 168 { 169 functions.append("function(data) { return data[" + i + "]},"); 170 } 171 functions.deleteCharAt(functions.length() - 1); 172 173 ScriptBuffer script = new ScriptBuffer(); 174 script.appendScript("dwr.util.addRows(") 175 .appendData(elementId) 176 .appendScript(",") 177 .appendData(data) 178 .appendScript(",") 179 .appendScript("[" + functions.toString() + "]") 180 .appendScript(options == null ? "" : ", " + options) 181 .appendScript(");"); 182 183 addScript(script); 184 } 185 } 186 187 193 public void addRows(String elementId, String [][] data) 194 { 195 addRows(elementId, data, null); 196 } 197 198 203 public void removeAllRows(String elementId) 204 { 205 addFunctionCall("dwr.util.removeAllRows", elementId); 206 } 207 208 213 public void cloneNode(String elementId) 214 { 215 addFunctionCall("dwr.util.cloneNode", elementId); 216 } 217 218 225 public void cloneNode(String elementId, String idPrefix, String idSuffix) 226 { 227 ScriptBuffer script = new ScriptBuffer(); 228 script.appendScript("dwr.util.cloneNode(") 229 .appendData(elementId) 230 .appendScript(", { idPrefix:") 231 .appendData(idPrefix) 232 .appendScript(", idSuffix:") 233 .appendData(idSuffix) 234 .appendScript("});"); 235 addScript(script); 236 } 237 238 244 public void removeNode(String elementId) 245 { 246 ScriptBuffer script = new ScriptBuffer(); 247 script.appendScript("dwr.util._temp = dwr.util.byId(") 248 .appendData(elementId) 249 .appendScript("); ") 250 .appendScript("if (dwr.util._temp) { dwr.util._temp.parentNode.removeChild(dwr.util._temp); dwr.util._temp = null; }"); 251 addScript(script); 252 } 253 254 259 public void setClassName(String elementId, String className) 260 { 261 addFunctionCall("dwr.util.setClassName", elementId, className); 262 } 263 264 269 public void addClassName(String elementId, String className) 270 { 271 addFunctionCall("dwr.util.addClassName", elementId, className); 272 } 273 274 279 public void removeClassName(String elementId, String className) 280 { 281 addFunctionCall("dwr.util.removeClassName", elementId, className); 282 } 283 284 289 public void toggleClassName(String elementId, String className) 290 { 291 addFunctionCall("dwr.util.toggleClassName", elementId, className); 292 } 293 294 300 public void setStyle(String elementId, String selector, String value) 301 { 302 ScriptBuffer script = new ScriptBuffer(); 303 script.appendScript("dwr.util.byId(") 304 .appendData(elementId) 305 .appendScript(").style.") 306 .appendScript(selector) 307 .appendScript("=") 308 .appendData(value) 309 .appendScript(";"); 310 addScript(script); 311 } 312 } 313 | Popular Tags |