1 16 package org.apache.taglibs.input; 17 18 import java.util.Map ; 19 20 import javax.servlet.ServletRequest ; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspTagException ; 23 import javax.servlet.jsp.JspWriter ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 36 37 public class Radio extends TagSupport { 38 39 private String name; 41 private String value; 43 private String dVal; 45 private Map attributes; 47 private String attributesText; 49 private String beanId; 51 public void release() { 52 super.release(); 53 name = null; 54 dVal = null; 55 attributes = null; 56 attributesText = null; 57 beanId = null; 58 } 59 60 public int doStartTag() throws JspException { 61 try { 62 if (name == null || name.equals("") || value == null) 64 throw new JspTagException ( 65 "invalid null or empty 'name' or 'value'"); 66 67 String beanId = this.beanId; 69 70 if (beanId == null) { 72 beanId = Util.defaultFormBeanId(this); 73 } else if (beanId.length() == 0) { 74 beanId = null; 76 } 77 78 ServletRequest req = pageContext.getRequest(); 80 JspWriter out = pageContext.getOut(); 81 82 out.print("<input type=\"radio\" "); 84 out.print("name=\"" + Util.quote(name) + "\" "); 85 out.print("value=\"" + Util.quote(value) + "\" "); 86 87 Util.printAttributes(out, attributes); 89 if (attributesText != null) { 90 out.print(attributesText + " "); 91 } 92 93 String target; 95 96 String beanValue = (beanId != null ? Util.beanPropertyValue( 98 pageContext.findAttribute(beanId), name) : null); 99 if (beanValue != null) { 100 target = beanValue; 101 } 102 else if (req.getParameter(name) == null) { 104 target = dVal; 105 } else { 106 target = req.getParameter(name); 107 } 108 109 if (target != null && target.equals(value)) 110 out.print("checked=\"checked\" "); 111 112 out.print("/>"); 114 115 } catch (Exception ex) { 116 throw new JspTagException (ex.getMessage()); 117 } 118 return SKIP_BODY; 119 } 120 121 public void setName(String x) { 122 name = x; 123 } 124 125 public void setValue(String x) { 126 value = x; 127 } 128 129 public void setAttributes(Map x) { 130 attributes = x; 131 } 132 133 public void setAttributesText(String x) { 134 attributesText = x; 135 } 136 137 public void setBean(String x) { 138 beanId = x; 139 } 140 141 public void setDefault(String x) { 142 dVal = x; 143 } 144 145 150 public String getName() { 151 return name; 152 } 153 154 159 public String getDefault() { 160 return dVal; 161 } 162 163 168 public String getBean() { 169 return beanId; 170 } 171 172 177 public String getAttributesText() { 178 return attributesText; 179 } 180 181 186 public Map getAttributes() { 187 return attributes; 188 } 189 } | Popular Tags |