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 Password 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 } 59 60 public int doStartTag() throws JspException { 61 try { 62 if (name == null || name.equals("")) 64 throw new JspTagException ("invalid null or empty 'name'"); 65 66 String beanId = this.beanId; 68 69 if (beanId == null) { 71 beanId = Util.defaultFormBeanId(this); 72 } else if (beanId.length() == 0) { 73 beanId = null; 75 } 76 77 ServletRequest req = pageContext.getRequest(); 79 JspWriter out = pageContext.getOut(); 80 81 out.print("<input type=\"password\" "); 83 out.print("name=\"" + Util.quote(name) + "\" "); 84 85 Util.printAttributes(out, attributes); 87 if (attributesText != null) { 88 out.print(attributesText + " "); 89 } 90 91 if (size != null) { 92 out.print("size=\"" + Util.quote(size) + "\" "); 93 } 94 95 99 String beanValue = (beanId != null ? Util.beanPropertyValue( 100 pageContext.findAttribute(beanId), name) : null); 101 if (beanValue != null) { 102 out.print("value=\"" + Util.quote(beanValue) + "\" "); 103 } else if (req.getParameter(name) != null) { 104 out.print("value=\"" + Util.quote(req.getParameter(name)) 105 + "\" "); 106 } else { 107 if (dVal != null) 108 out.print("value=\"" + Util.quote(dVal) + "\" "); 109 else 110 out.print("value=\"\" "); 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 setAttributes(Map x) { 126 attributes = x; 127 } 128 129 public void setAttributesText(String x) { 130 attributesText = x; 131 } 132 133 public void setBean(String x) { 134 beanId = x; 135 } 136 137 public void setDefault(String x) { 138 dVal = x; 139 } 140 141 146 public String getName() { 147 return name; 148 } 149 150 155 public String getDefault() { 156 return dVal; 157 } 158 159 164 public String getBean() { 165 return beanId; 166 } 167 168 173 public String getAttributesText() { 174 return attributesText; 175 } 176 177 182 public Map getAttributes() { 183 return attributes; 184 } 185 186 public void setSize(String size) { 187 this.size = size; 188 } 189 } | Popular Tags |