1 15 package net.mlw.vlh.web.tag; 16 17 import java.util.HashMap ; 18 19 import javax.servlet.jsp.JspException ; 20 21 import net.mlw.vlh.web.tag.support.ParamAddable; 22 import net.mlw.vlh.web.util.JspUtils; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 43 public class ActionTag extends ConfigurableTag implements ParamAddable 44 { 45 46 private static final long serialVersionUID = -4765405639511065820L; 47 48 51 private static final Log LOGGER = LogFactory.getLog(ActionTag.class); 52 53 57 private String url = null; 58 59 60 private HashMap customParameters = null; 61 62 66 private HashMap actionParameters = new HashMap (); 67 68 73 public static final String ACTION_TEMP_PARAM_PREFIX = "ACT"; 74 75 public int doStartTag() throws JspException 76 { 77 actionParameters.clear(); 78 return super.doStartTag(); 79 } 80 81 public int doEndTag() throws JspException 82 { 83 84 ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class); 85 86 StringBuffer sb = new StringBuffer ("<a "); 87 sb.append(getCellAttributes().getCellAttributesAsString()); 88 89 sb.append("href=\""); 90 sb.append(getUrl(rootTag)); 91 92 sb.append(rootTag.getTableInfo().getConfig().getLinkEncoder().encode(pageContext, getAllParameters(rootTag))); 93 sb.append("\">"); 94 sb.append(bodyContent.getString().trim()); 95 sb.append("</a>"); 96 JspUtils.write(pageContext, sb.toString()); 97 98 release(); 99 100 return EVAL_PAGE; 101 } 102 103 109 private HashMap getAllParameters(ValueListSpaceTag rootTag) 110 { 111 HashMap map = new HashMap (); 112 if (rootTag.getTableInfo().getParameters() != null) 113 { 114 map.putAll(rootTag.getTableInfo().getParameters()); 115 } 116 if (customParameters != null) 120 { 121 map.putAll(customParameters); 122 } 123 124 map.putAll(actionParameters); 126 return map; 127 } 128 129 133 public void setCustomParameters(HashMap customParameters) 134 { 135 this.customParameters = customParameters; 136 } 137 138 141 private String getUrl(ValueListSpaceTag rootTag) 142 { 143 if (url == null) 144 { 145 return rootTag.getTableInfo().getUrl(); 146 } 147 else 148 { 149 return url; 150 } 151 } 152 153 156 public void setUrl(String url) 157 { 158 this.url = url; 159 } 160 161 174 public void addParam(String key, String value) 175 { 176 if (LOGGER.isDebugEnabled() && value == null) 177 { 178 LOGGER.debug("Do you really want to add param '" + key + "' which value is null?"); 179 } 180 actionParameters.put(key, value); 181 } 182 183 private void reset() 184 { 185 this.actionParameters.clear(); 186 this.customParameters = null; 187 this.url = null; 188 } 189 190 198 public void release() 199 { 200 super.release(); 201 reset(); 202 } 203 } | Popular Tags |