1 16 package org.apache.taglibs.input; 17 18 import java.util.Map ; 19 20 import javax.servlet.http.HttpServletResponse ; 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 Form extends TagSupport { 38 39 private String name; 41 private String action; 43 private Map attributes; 45 private String attributesText; 47 private String beanId; 49 private String method; 51 private String encType; 53 public void release() { 54 super.release(); 55 name = null; 56 action = null; 57 attributes = null; 58 attributesText = null; 59 beanId = null; 60 method = null; 61 encType = null; 62 } 63 64 public int doStartTag() throws JspException { 65 try { 66 JspWriter out = pageContext.getOut(); 68 69 out.print("<form method=\""); 71 out.print(method != null ? method : "get"); 72 out.print("\" action=\""); 73 if (action != null) { 74 if (action.length() > 0 75 && pageContext.getResponse() instanceof HttpServletResponse ) { 76 out.print(((HttpServletResponse ) pageContext.getResponse()) 77 .encodeURL(action)); 78 } else { 79 out.print(action); 80 } 81 } 82 out.print("\" "); 83 if (name != null) { 84 out.print("name=\"" + Util.quote(name) + "\" "); 85 } 86 if (encType != null) { 87 out.print("enctype=\"" + encType + "\" "); 88 } 89 90 Util.printAttributes(out, attributes); 92 if (attributesText != null) { 93 out.print(attributesText + " "); 94 } 95 96 out.print(">"); 98 99 } catch (Exception ex) { 100 throw new JspTagException (ex.getMessage()); 101 } 102 return EVAL_BODY_INCLUDE; 103 } 104 105 public int doEndTag() throws JspException { 106 try { 107 JspWriter out = pageContext.getOut(); 108 out.print("</form>"); 109 } catch (Exception ex) { 110 throw new JspTagException (ex.getMessage()); 111 } 112 return EVAL_PAGE; 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 String getBean() { 132 return beanId; 133 } 134 135 public void setAction(String x) { 136 action = x; 137 } 138 139 public void setMethod(String x) { 140 method = x; 141 } 142 143 public void setEncType(String x) { 144 encType = x; 145 } 146 147 152 public String getName() { 153 return name; 154 } 155 156 161 public String getMethod() { 162 return method; 163 } 164 165 170 public String getEncType() { 171 return encType; 172 } 173 174 179 public String getAttributesText() { 180 return attributesText; 181 } 182 183 188 public Map getAttributes() { 189 return attributes; 190 } 191 192 197 public String getAction() { 198 return action; 199 } 200 201 } | Popular Tags |