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 Hidden extends TagSupport { 38 39 private String name; 41 private String dVal; 43 private Map attributes; 45 private String attributesText; 47 private String beanId; 49 public void release() { 50 super.release(); 51 name = null; 52 dVal = null; 53 attributes = null; 54 attributesText = null; 55 beanId = null; 56 } 57 58 public int doStartTag() throws JspException { 59 try { 60 if (name == null || name.equals("")) 62 throw new JspTagException ("invalid null or empty 'name'"); 63 64 String beanId = this.beanId; 66 67 if (beanId == null) { 69 beanId = Util.defaultFormBeanId(this); 70 } else if (beanId.length() == 0) { 71 beanId = null; 73 } 74 75 ServletRequest req = pageContext.getRequest(); 77 JspWriter out = pageContext.getOut(); 78 79 out.print("<input type=\"hidden\" "); 81 out.print("name=\"" + Util.quote(name) + "\" "); 82 83 Util.printAttributes(out, attributes); 85 if (attributesText != null) { 86 out.print(attributesText + " "); 87 } 88 89 93 String beanValue = (beanId != null ? Util.beanPropertyValue( 94 pageContext.findAttribute(beanId), name) : null); 95 if (beanValue != null) { 96 out.print("value=\"" + Util.quote(beanValue) + "\" "); 97 } else if (req.getParameter(name) != null) { 98 out.print("value=\"" + Util.quote(req.getParameter(name)) 99 + "\" "); 100 } else { 101 if (dVal != null) 102 out.print("value=\"" + Util.quote(dVal) + "\" "); 103 else 104 out.print("value=\"\" "); 105 } 106 out.print("/>"); 108 109 } catch (Exception ex) { 110 throw new JspTagException (ex.getMessage()); 111 } 112 return SKIP_BODY; 113 } 114 115 public void setName(String x) { 116 name = x; 117 } 118 119 public void setAttributes(Map x) { 120 attributes = x; 121 } 122 123 public void setAttributesText(String x) { 124 attributesText = x; 125 } 126 127 public void setBean(String x) { 128 beanId = x; 129 } 130 131 public void setDefault(String x) { 132 dVal = x; 133 } 134 135 140 public String getName() { 141 return name; 142 } 143 144 149 public String getDefault() { 150 return dVal; 151 } 152 153 158 public String getBean() { 159 return beanId; 160 } 161 162 167 public String getAttributesText() { 168 return attributesText; 169 } 170 171 176 public Map getAttributes() { 177 return attributes; 178 } 179 } | Popular Tags |