1 25 29 package org.jresearch.gossip.tags; 30 31 import java.util.ArrayList ; 32 import java.util.Enumeration ; 33 34 import javax.servlet.ServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 import javax.servlet.jsp.JspException ; 37 import javax.servlet.jsp.tagext.TagSupport ; 38 39 import org.jresearch.gossip.IConst; 40 import org.jresearch.gossip.list.RecordsData; 41 42 47 public class BlockOptionsTag extends TagSupport { 48 49 private String id; 50 51 59 public int doStartTag() throws JspException { 60 try { 61 if (pageContext.getAttribute(id) != null) { 62 return (SKIP_BODY); 63 } 64 HttpServletResponse response = (HttpServletResponse ) pageContext 65 .getResponse(); 66 ServletRequest req = pageContext.getRequest(); 67 Enumeration pnames = req.getParameterNames(); 68 StringBuffer url = new StringBuffer ((String ) req 69 .getAttribute(IConst.REQUEST.REQUEST_URI) 70 + "?"); 71 72 while (pnames.hasMoreElements()) { 73 String name = (String ) pnames.nextElement(); 74 75 if (!name.equals("block") && req.getParameter(name) != null 76 && !req.getParameter(name).equals("")) { 77 url.append(name); 78 url.append("="); 79 url.append(req.getParameter(name)); 80 81 if (pnames.hasMoreElements()) { 82 url.append("&"); 83 } 84 } 85 } 86 87 RecordsData recordsData = (RecordsData) req 88 .getAttribute(IConst.REQUEST.RECORDS_DATA); 89 ArrayList options = new ArrayList (); 90 91 int i = 0; 92 93 while (i < recordsData.getRecordsCount()) { 94 int endRecord = ((i + recordsData.getBlockSize()) < recordsData 95 .getRecordsCount()) ? (i + recordsData.getBlockSize()) 96 : recordsData.getRecordsCount(); 97 OptionBean ob = new OptionBean(); 98 99 ob.setProperty(response.encodeURL(url.toString() + "&block=" 100 + i)); 101 ob.setLabelProperty((i + 1) + "-" + endRecord); 102 options.add(ob); 103 104 if (i == recordsData.getCurrBlock()) { 105 pageContext.setAttribute(IConst.PAGE.SELECTED_BLOCK, ob); 106 } 107 108 i = endRecord; 109 } 110 111 pageContext.setAttribute(id, options); 112 } catch (Exception ex) { 113 throw new JspException ("error in BlockOptionsTag tag:", ex); 114 } 115 116 return (SKIP_BODY); 117 } 118 119 124 public String getId() { 125 return id; 126 } 127 128 133 public void setId(String string) { 134 id = string; 135 } 136 } | Popular Tags |