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 Text extends TagSupport { 38 39 private String name; 41 private String dVal; 43 private Map attributes; 45 private String attributesText; 47 private String beanId; 49 private String size; 50 51 public void release() { 52 super.release(); 53 name = null; 54 dVal = null; 55 attributes = null; 56 attributesText = null; 57 beanId = null; 58 size = null; 59 } 60 61 public int doStartTag() throws JspException { 62 try { 63 if (name == null || name.equals("")) 65 throw new JspTagException ("invalid null or empty 'name'"); 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=\"text\" "); 84 out.print("name=\"" + Util.quote(name) + "\" "); 85 86 Util.printAttributes(out, attributes); 88 if (attributesText != null) { 89 out.print(attributesText + " "); 90 } 91 92 if (size != null) { 93 out.print("size=\"" + Util.quote(size) + "\" "); 94 } 95 96 100 String beanValue = (beanId != null ? Util.beanPropertyValue( 101 pageContext.findAttribute(beanId), name) : null); 102 if (beanValue != null) { 103 out.print("value=\"" + Util.quote(beanValue) + "\" "); 104 } else if (req.getParameter(name) != null) { 105 out.print("value=\"" + Util.quote(req.getParameter(name)) 106 + "\" "); 107 } else { 108 if (dVal != null) 109 out.print("value=\"" + Util.quote(dVal) + "\" "); 110 else 111 out.print("value=\"\" "); 112 } 113 out.print("/>"); 115 116 } catch (Exception ex) { 117 throw new JspTagException (ex.getMessage()); 118 } 119 return SKIP_BODY; 120 } 121 122 public void setName(String x) { 123 name = x; 124 } 125 126 public void setAttributes(Map x) { 127 attributes = x; 128 } 129 130 public void setAttributesText(String x) { 131 attributesText = x; 132 } 133 134 public void setBean(String x) { 135 beanId = x; 136 } 137 138 public void setDefault(String x) { 139 dVal = x; 140 } 141 142 147 public String getName() { 148 return name; 149 } 150 151 156 public String getDefault() { 157 return dVal; 158 } 159 160 165 public String getBean() { 166 return beanId; 167 } 168 169 174 public String getAttributesText() { 175 return attributesText; 176 } 177 178 183 public Map getAttributes() { 184 return attributes; 185 } 186 187 public void setSize(String size) { 188 this.size = size; 189 } 190 } | Popular Tags |