Changeset 158
- Timestamp:
- 08/16/08 18:21:23 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
core/trunk/src/main/java/org/restafarian/core/servlets/SelectListServletBase.java
r7 r158 29 29 */ 30 30 public abstract class SelectListServletBase extends RestServletBase { 31 private static final String FIELD_MAP_REQ_ATTR_KEY = "select.list.data.field.map"; 31 32 private String contextKey = ""; 32 33 private String dataSourceName = ""; … … 47 48 StringBuffer buffer = new StringBuffer(); 48 49 50 req.setAttribute(FIELD_MAP_REQ_ATTR_KEY, getCurrentDataFields(req)); 49 51 buffer.append("<?xml version=\"1.0\"?>\n"); 50 52 buffer.append("<options size=\""); … … 100 102 101 103 /** 104 * <p>This method returns the current map of data fields.</p> 105 * 106 * @param req the <code>HttpServletRequest</code> object 107 * @return the current map of data fields 108 */ 109 protected Map getCurrentDataFields(HttpServletRequest req) { 110 return dataFields; 111 } 112 113 /** 102 114 * <p>This method formats the options.</p> 103 115 * … … 130 142 } 131 143 144 Map fields = (Map) req.getAttribute(FIELD_MAP_REQ_ATTR_KEY); 132 145 for (int x=startIndex; x<endIndex; x++) { 133 146 int index = x + 1; … … 136 149 buffer.append(index); 137 150 buffer.append("\">\n"); 138 Iterator i = dataFields.keySet().iterator();151 Iterator i = fields.keySet().iterator(); 139 152 while (i.hasNext()) { 140 153 String fieldName = (String) i.next(); … … 183 196 results.put("accessCount", new Integer(accessCount.intValue() + 1)); 184 197 } else { 185 options = fetchOptions( startsWith, contains, orderBy);198 options = fetchOptions(req, startsWith, contains, orderBy); 186 199 if (options != null && options.size() > 0) { 187 200 Map results = new HashMap(); … … 210 223 * <p>This method obtains the requested options from the data source.</p> 211 224 * 225 * @param req the <code>HttpServletRequest</code> object 212 226 * @param startsWith the "starts with" query parameter 213 227 * @param contains the "contains" query parameter … … 215 229 * @return the options 216 230 */ 217 protected List fetchOptions( String startsWith, String contains, String orderBy) {231 protected List fetchOptions(HttpServletRequest req, String startsWith, String contains, String orderBy) { 218 232 List options = new ArrayList(); 219 233 … … 222 236 Statement stmt = null; 223 237 ResultSet rs = null; 224 String qs = getQueryStatement( startsWith, contains, orderBy);238 String qs = getQueryStatement(req, startsWith, contains, orderBy); 225 239 Map items = new TreeMap(); 240 Map fields = (Map) req.getAttribute(FIELD_MAP_REQ_ATTR_KEY); 226 241 try { 227 242 conn = dataSource.getConnection(); … … 231 246 while (rs.next()) { 232 247 Map thisItem = new HashMap(); 233 Iterator i = dataFields.keySet().iterator();248 Iterator i = fields.keySet().iterator(); 234 249 while (i.hasNext()) { 235 250 String fieldName = (String) i.next(); 236 String tableField = (String) dataFields.get(fieldName);251 String tableField = (String) fields.get(fieldName); 237 252 thisItem.put(fieldName, filter(rs.getString(tableField))); 238 253 } … … 294 309 * <p>This method creates the SQL statement.</p> 295 310 * 311 * @param req the <code>HttpServletRequest</code> object 312 * @param startsWith the "starts with" query parameter 313 * @param contains the "contains" query parameter 314 * @param orderBy the sort order 315 * @return the SQL statement 316 */ 317 protected String getQueryStatement(HttpServletRequest req, String startsWith, String contains, String orderBy) { 318 return getQueryStatement(startsWith, contains, orderBy); 319 } 320 321 /** 322 * <p>This method creates the SQL statement.</p> 323 * 296 324 * @param startsWith the "starts with" query parameter 297 325 * @param contains the "contains" query parameter … … 383 411 * @return Returns the contextKey. 384 412 */ 385 p rotectedString getContextKey() {413 public String getContextKey() { 386 414 return contextKey; 387 415 } … … 389 417 * @param contextKey The contextKey to set. 390 418 */ 391 p rotectedvoid setContextKey(String contextKey) {419 public void setContextKey(String contextKey) { 392 420 this.contextKey = contextKey; 393 421 } … … 395 423 * @return Returns the dataFields. 396 424 */ 397 p rotectedMap getDataFields() {425 public Map getDataFields() { 398 426 return dataFields; 399 427 } … … 401 429 * @param dataFields The dataFields to set. 402 430 */ 403 p rotectedvoid setDataFields(Map dataFields) {431 public void setDataFields(Map dataFields) { 404 432 this.dataFields = dataFields; 405 433 } … … 407 435 * @return Returns the dataSourceName. 408 436 */ 409 p rotectedString getDataSourceName() {437 public String getDataSourceName() { 410 438 return dataSourceName; 411 439 } … … 413 441 * @param dataSourceName The dataSourceName to set. 414 442 */ 415 p rotectedvoid setDataSourceName(String dataSourceName) {443 public void setDataSourceName(String dataSourceName) { 416 444 this.dataSourceName = dataSourceName; 417 445 } … … 419 447 * @return Returns the defaultContains. 420 448 */ 421 p rotectedString getDefaultContains() {449 public String getDefaultContains() { 422 450 return defaultContains; 423 451 } … … 425 453 * @param defaultContains The defaultContains to set. 426 454 */ 427 p rotectedvoid setDefaultContains(String defaultContains) {455 public void setDefaultContains(String defaultContains) { 428 456 this.defaultContains = defaultContains; 429 457 } … … 431 459 * @return Returns the defaultOrderBy. 432 460 */ 433 p rotectedString getDefaultOrderBy() {461 public String getDefaultOrderBy() { 434 462 return defaultOrderBy; 435 463 } … … 437 465 * @param defaultOrderBy The defaultOrderBy to set. 438 466 */ 439 p rotectedvoid setDefaultOrderBy(String defaultOrderBy) {467 public void setDefaultOrderBy(String defaultOrderBy) { 440 468 this.defaultOrderBy = defaultOrderBy; 441 469 } … … 443 471 * @return Returns the defaultStartsWith. 444 472 */ 445 p rotectedString getDefaultStartsWith() {473 public String getDefaultStartsWith() { 446 474 return defaultStartsWith; 447 475 } … … 449 477 * @param defaultStartsWith The defaultStartsWith to set. 450 478 */ 451 p rotectedvoid setDefaultStartsWith(String defaultStartsWith) {479 public void setDefaultStartsWith(String defaultStartsWith) { 452 480 this.defaultStartsWith = defaultStartsWith; 453 481 }