1 18 19 package org.apache.struts.taglib.html; 20 21 import javax.servlet.jsp.JspException ; 22 23 import org.apache.struts.taglib.TagUtils; 24 import org.apache.struts.util.MessageResources; 25 26 31 public class RadioTag extends BaseHandlerTag { 32 33 34 36 37 40 protected static MessageResources messages = 41 MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); 42 43 44 47 protected String name = Constants.BEAN_KEY; 48 49 public String getName() { 50 return (this.name); 51 } 52 53 public void setName(String name) { 54 this.name = name; 55 } 56 57 58 61 protected String property = null; 62 63 64 67 protected String text = null; 68 69 70 73 protected String value = null; 74 75 76 86 protected String idName = null; 87 88 89 91 92 95 public String getProperty() { 96 97 return (this.property); 98 99 } 100 101 106 public void setProperty(String property) { 107 108 this.property = property; 109 110 } 111 112 115 public String getValue() { 116 117 return (this.value); 118 119 } 120 121 126 public void setValue(String value) { 127 128 this.value = value; 129 130 } 131 132 136 public String getIdName() { 137 138 return (this.idName); 139 140 } 141 142 148 public void setIdName(String idName) { 149 150 this.idName=idName; 151 152 } 153 154 155 157 158 164 public int doStartTag() throws JspException { 165 166 String radioTag = renderRadioElement(serverValue(), currentValue()); 167 168 TagUtils.getInstance().write(pageContext, radioTag); 169 170 this.text = null; 171 return (EVAL_BODY_TAG); 172 } 173 174 179 private String serverValue() throws JspException { 180 181 if (this.idName == null) { 183 return this.value; 184 } 185 186 String serverValue = this.lookupProperty(this.idName, this.value); 187 188 return (serverValue == null) ? "" : serverValue; 189 } 190 191 197 private String currentValue() throws JspException { 198 String current = this.lookupProperty(this.name, this.property); 199 200 return (current == null) ? "" : current; 201 } 202 203 213 protected String renderRadioElement(String serverValue, String checkedValue) 214 throws JspException { 215 216 StringBuffer results = new StringBuffer ("<input type=\"radio\""); 217 218 prepareAttribute(results, "name", prepareName()); 219 prepareAttribute(results, "accesskey", getAccesskey()); 220 prepareAttribute(results, "tabindex", getTabindex()); 221 prepareAttribute(results, "value", serverValue); 222 if (serverValue.equals(checkedValue)) { 223 results.append(" checked=\"checked\""); 224 } 225 results.append(prepareEventHandlers()); 226 results.append(prepareStyles()); 227 prepareOtherAttributes(results); 228 results.append(getElementClose()); 229 return results.toString(); 230 } 231 232 237 public int doAfterBody() throws JspException { 238 239 if (this.bodyContent != null) { 240 String value = this.bodyContent.getString().trim(); 241 if (value.length() > 0) { 242 this.text = value; 243 } 244 } 245 246 return (SKIP_BODY); 247 } 248 249 254 public int doEndTag() throws JspException { 255 256 if (this.text != null) { 258 TagUtils.getInstance().write(pageContext, text); 259 } 260 261 return (EVAL_PAGE); 262 263 } 264 265 266 270 protected String prepareName() throws JspException { 271 272 if (property == null) { 273 return null; 274 } 275 276 if(indexed) { 278 StringBuffer results = new StringBuffer (); 279 prepareIndex(results, name); 280 results.append(property); 281 return results.toString(); 282 } 283 284 return property; 285 286 } 287 288 291 public void release() { 292 293 super.release(); 294 idName = null; 295 name = Constants.BEAN_KEY; 296 property = null; 297 text = null; 298 value = null; 299 300 } 301 302 } 303 | Popular Tags |