1 21 package net.mlw.vlh.web.tag; 22 23 import java.text.MessageFormat ; 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.StringTokenizer ; 29 30 import javax.servlet.jsp.JspException ; 31 import javax.servlet.jsp.tagext.BodyContent ; 32 import javax.servlet.jsp.tagext.BodyTagSupport ; 33 34 import net.mlw.vlh.ValueListInfo; 35 import net.mlw.vlh.web.util.JspUtils; 36 37 42 public class FilterListTag extends BodyTagSupport 43 { 44 45 private static final String DEFAULT_TOKEN = "|"; 46 47 private String token = DEFAULT_TOKEN; 48 49 private String key; 50 51 private String format; 52 53 private Map parameters; 54 55 private ValueListSpaceTag rootTag; 56 57 60 public int doStartTag() throws JspException 61 { 62 rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class); 63 parameters = new HashMap (rootTag.getTableInfo().getParameters()); 64 return super.doStartTag(); 65 } 66 67 70 public int doAfterBody() throws JspException 71 { 72 BodyContent body = getBodyContent(); 73 if (body != null) 74 { 75 List ignoreList = new ArrayList (); 76 ignoreList.add(getKey()); 77 78 TableInfo tableInfo = rootTag.getTableInfo(); 79 80 parameters.remove(ValueListInfo.PAGING_PAGE + tableInfo.getId()); 82 83 String content = body.getString().trim(); 84 String valueInRequest = pageContext.getRequest().getParameter(getKey() + tableInfo.getId()); 85 JspUtils.writePrevious(pageContext, "<table class=\"filters\" width=\"100%\"><tr>"); 86 for (StringTokenizer st = new StringTokenizer (content, getToken()); st.hasMoreTokens();) 87 { 88 String token = st.nextToken(); 89 String value = (format == null) ? token : MessageFormat.format(format, new String [] 90 { token }); 91 92 boolean selected = value.equals(valueInRequest); 93 94 parameters.put(getKey() + tableInfo.getId(), value); 95 96 JspUtils.writePrevious(pageContext, (selected ? "<th>" : "<td>") + "<a HREF=\"" + tableInfo.getUrl() 97 + rootTag.getConfig().getLinkEncoder().encode(pageContext, parameters) + "\">"); 98 JspUtils.writePrevious(pageContext, token); 99 JspUtils.writePrevious(pageContext, "</a>" + (selected ? "</th>" : "</td>")); 100 } 101 JspUtils.writePrevious(pageContext, "</tr></table>"); 102 103 } 104 return SKIP_BODY; 105 } 106 107 110 public int doEndTag() throws JspException 111 { 112 int result = super.doEndTag(); 113 reset(); 114 return result; 115 } 116 117 120 public String getKey() 121 { 122 return key; 123 } 124 125 129 public void setKey(String key) 130 { 131 this.key = key; 132 } 133 134 137 public String getToken() 138 { 139 return token; 140 } 141 142 146 public void setToken(String token) 147 { 148 this.token = token; 149 } 150 151 154 public String getFormat() 155 { 156 return format; 157 } 158 159 163 public void setFormat(String format) 164 { 165 this.format = format; 166 } 167 168 private void reset() 169 { 170 this.rootTag = null; 171 this.format = null; 172 this.key = null; 173 this.parameters = null; 174 this.token = DEFAULT_TOKEN; 175 } 176 177 185 public void release() 186 { 187 super.release(); 188 reset(); 189 } 190 } | Popular Tags |