1 21 22 package org.opensubsystems.patterns.scrollabletable.www; 23 24 import javax.servlet.jsp.JspException ; 25 26 import org.opensubsystems.core.www.PageElementCacheTag; 27 import org.opensubsystems.core.www.TagUtils; 28 29 53 public class ScrollableTableJSTag extends PageElementCacheTag 54 { 55 57 60 private static final long serialVersionUID = -2507154189971104193L; 61 62 66 protected String m_strFunction; 67 68 71 protected String m_strParam1; 72 73 76 protected int m_iParam2; 77 78 81 protected int m_iParam3; 82 83 85 88 public ScrollableTableJSTag() 89 { 90 super(); 91 m_strParam1 = null; 92 m_iParam2 = 0; 93 m_iParam3 = 0; 94 } 95 96 98 101 public int doStartTag( 102 ) throws JspException 103 { 104 StringBuffer sbHtml = new StringBuffer (); 105 106 if (("onload".equalsIgnoreCase(m_strFunction)) 107 || ("onresize".equalsIgnoreCase(m_strFunction))) 108 { 109 if ((m_strParam1 == null) || (m_strParam1.length() == 0)) 110 { 111 m_strParam1 = "fixed"; 113 } 114 if ((m_iParam2 <= 0)) 115 { 116 m_iParam2 = 200; 118 } 119 120 149 150 if ("fill".equalsIgnoreCase(m_strParam1)) 153 { 154 sbHtml.append("var iContentAreaHeight"); 155 sbHtml.append(m_strId); 156 sbHtml.append(";\n"); 157 sbHtml.append("var bExact"); 158 sbHtml.append(m_strId); 159 sbHtml.append(" = false;\n"); 160 sbHtml.append("iContentAreaHeight"); 161 sbHtml.append(m_strId); 162 sbHtml.append(" = resizeScrollableTableContentArea('"); 163 sbHtml.append(m_strId); 164 sbHtml.append("');\n"); 165 } 166 else if ("fixed".equalsIgnoreCase(m_strParam1)) 167 { 168 if ("onload".equalsIgnoreCase(m_strFunction)) 169 { 170 if (m_iParam3 <= 0) 171 { 172 sbHtml.append("<!-- Unknown number of rows for table with fixed" + 173 " size, use param3 to specify number of rows -->\n"); 174 m_iParam3 = 0; 175 } 176 sbHtml.append("iRowsNumber[getTableIndex('"); 178 sbHtml.append(m_strId); 179 sbHtml.append("')] = "); 180 sbHtml.append(m_iParam3); 181 sbHtml.append(";\n"); 182 } 183 184 sbHtml.append("var iContentAreaHeight"); 185 sbHtml.append(m_strId); 186 sbHtml.append(" = "); 187 sbHtml.append(m_iParam2); 188 sbHtml.append(";\n"); 189 sbHtml.append("var bExact"); 190 sbHtml.append(m_strId); 191 sbHtml.append(" = true;\n"); 192 } 193 else 194 { 195 throw new JspException ("For method " + m_strFunction 196 + " param2 has to be either fixed or fill."); 197 } 198 sbHtml.append("var arColumnsSizes"); 199 sbHtml.append(m_strId); 200 sbHtml.append(";\n"); 201 202 sbHtml.append("resizeScrollableTable('"); 203 sbHtml.append(m_strId); 204 sbHtml.append("', iContentAreaHeight"); 205 sbHtml.append(m_strId); 206 sbHtml.append(", bExact"); 207 sbHtml.append(m_strId); 208 sbHtml.append(");\n"); 209 210 sbHtml.append("arColumnsSizes"); 211 sbHtml.append(m_strId); 212 sbHtml.append(" = retrieveColumnHeadingSizes('"); 213 sbHtml.append(m_strId); 214 sbHtml.append("bodycolumns');\n"); 215 216 sbHtml.append("setColumnHeadingSizes('"); 217 sbHtml.append(m_strId); 218 sbHtml.append("header', arColumnsSizes"); 219 sbHtml.append(m_strId); 220 sbHtml.append(");"); 221 } 222 else 223 { 224 sbHtml.append("<!-- Scrollable table doesn't support method "); 225 sbHtml.append(m_strFunction); 226 sbHtml.append(" with parameters "); 227 if (m_strId != null) 228 { 229 sbHtml.append(" param1="); 230 sbHtml.append(m_strParam1); 231 sbHtml.append(" "); 232 } 233 else 234 { 235 sbHtml.append(" param1=null "); 236 } 237 sbHtml.append(" param2="); 238 sbHtml.append(m_iParam2); 239 sbHtml.append(" "); 240 sbHtml.append(" -->"); 241 } 242 243 TagUtils.write(pageContext, sbHtml.toString()); 244 245 return (SKIP_BODY); 246 } 247 248 251 public int doEndTag( 252 ) throws JspException 253 { 254 return (EVAL_PAGE); 255 } 256 257 261 public String getFunction( 262 ) 263 { 264 return m_strFunction; 265 } 266 267 270 public String getParam1( 271 ) 272 { 273 return m_strParam1; 274 } 275 276 279 public int getParam2( 280 ) 281 { 282 return m_iParam2; 283 } 284 285 288 public int getParam3( 289 ) 290 { 291 return m_iParam3; 292 } 293 294 299 public void setFunction( 300 String strFunction 301 ) 302 { 303 m_strFunction = strFunction; 304 } 305 306 309 public void setParam1( 310 String strParam1 311 ) 312 { 313 m_strParam1 = strParam1; 314 } 315 316 319 public void setParam2( 320 int iParam2 321 ) 322 { 323 m_iParam2 = iParam2; 324 } 325 326 329 public void setParam3( 330 int iParam3 331 ) 332 { 333 m_iParam3 = iParam3; 334 } 335 } 336 | Popular Tags |