1 7 package org.ejtools.servlet.http.jsp.tagext; 8 9 import javax.servlet.jsp.JspException ; 10 import javax.servlet.jsp.tagext.TagSupport ; 11 12 import org.ejtools.util.ClassTools; 13 14 30 public class RequestParameterTag extends TagSupport 31 { 32 33 protected String id = null; 34 35 protected String name = null; 36 37 protected String type = null; 38 39 protected String value = null; 40 41 42 48 public int doStartTag() 49 throws JspException 50 { 51 String s = null; 52 53 s = pageContext.getRequest().getParameter(this.name); 54 55 if ((s == null) && (this.value == null)) 56 { 57 throw new JspException ("Request parameter " + this.name + " not found and value is not provided"); 58 } 59 60 if (s == null) 61 { 62 s = this.value; 63 } 64 Object object = this.convert(s, this.type); 65 66 pageContext.setAttribute(this.id, object); 68 69 return (SKIP_BODY); 71 } 72 73 74 82 public String getId() 83 { 84 return this.id; 85 } 86 87 88 96 public String getName() 97 { 98 return this.name; 99 } 100 101 102 110 public String getType() 111 { 112 return this.type; 113 } 114 115 116 124 public String getValue() 125 { 126 return this.value; 127 } 128 129 130 131 public void release() 132 { 133 super.release(); 134 this.id = null; 135 this.name = null; 136 this.type = null; 137 this.value = null; 138 } 139 140 141 146 public void setId(String id) 147 { 148 this.id = id; 149 } 150 151 152 157 public void setName(String name) 158 { 159 this.name = name; 160 } 161 162 163 168 public void setType(String type) 169 { 170 this.type = type; 171 } 172 173 174 179 public void setValue(String value) 180 { 181 this.value = value; 182 } 183 184 185 192 protected Object convert(String s, String type) 193 { 194 Class c = ClassTools.getClass(type); 195 196 if (c == Boolean .class) 197 { 198 return new Boolean (s); 199 } 200 if (c == Byte .class) 201 { 202 return new Byte (Byte.parseByte(s)); 203 } 204 if (c == Double .class) 205 { 206 return new Double (Double.parseDouble(s)); 207 } 208 if (c == Float .class) 209 { 210 return new Float (Float.parseFloat(s)); 211 } 212 if (c == Integer .class) 213 { 214 return new Integer (Integer.parseInt(s)); 215 } 216 if (c == Long .class) 217 { 218 return new Long (Long.parseLong(s)); 219 } 220 return s; 221 } 222 } 223 224 | Popular Tags |