KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > input > Form


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.taglibs.input;
17
18 import java.util.Map JavaDoc;
19
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.JspTagException JavaDoc;
23 import javax.servlet.jsp.JspWriter JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 /**
27  *
28  * This class implements the <input:form> tag, which presents an <form
29  * ... /> element.
30  *
31  * @version 0.90
32  * @author Shawn Bayern
33  * @author Lance Lavandowska
34  * @author Karl von Randow
35  */

36
37 public class Form extends TagSupport JavaDoc {
38
39     private String JavaDoc name; // name of the form
40

41     private String JavaDoc action; // form action
42

43     private Map JavaDoc attributes; // attributes of the <input> element
44

45     private String JavaDoc attributesText; // attributes of the <input> element as text
46

47     private String JavaDoc beanId; // bean id to get default values from
48

49     private String JavaDoc method; // form method
50

51     private String JavaDoc encType; // form encType
52

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 JavaDoc {
65         try {
66             // get what we need from the page
67
JspWriter JavaDoc out = pageContext.getOut();
68
69             // start building up the tag
70
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 JavaDoc) {
76                     out.print(((HttpServletResponse JavaDoc) 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             // include any attributes we've got here
91
Util.printAttributes(out, attributes);
92             if (attributesText != null) {
93                 out.print(attributesText + " ");
94             }
95
96             // end the tag
97
out.print(">");
98
99         } catch (Exception JavaDoc ex) {
100             throw new JspTagException JavaDoc(ex.getMessage());
101         }
102         return EVAL_BODY_INCLUDE;
103     }
104
105     public int doEndTag() throws JspException JavaDoc {
106         try {
107             JspWriter JavaDoc out = pageContext.getOut();
108             out.print("</form>");
109         } catch (Exception JavaDoc ex) {
110             throw new JspTagException JavaDoc(ex.getMessage());
111         }
112         return EVAL_PAGE;
113     }
114
115     public void setName(String JavaDoc x) {
116         name = x;
117     }
118
119     public void setAttributes(Map JavaDoc x) {
120         attributes = x;
121     }
122
123     public void setAttributesText(String JavaDoc x) {
124         attributesText = x;
125     }
126
127     public void setBean(String JavaDoc x) {
128         beanId = x;
129     }
130
131     public String JavaDoc getBean() {
132         return beanId;
133     }
134
135     public void setAction(String JavaDoc x) {
136         action = x;
137     }
138
139     public void setMethod(String JavaDoc x) {
140         method = x;
141     }
142
143     public void setEncType(String JavaDoc x) {
144         encType = x;
145     }
146
147     /**
148      * Getter for property name.
149      *
150      * @return Value of property name.
151      */

152     public String JavaDoc getName() {
153         return name;
154     }
155
156     /**
157      * Getter for property method.
158      *
159      * @return Value of property method.
160      */

161     public String JavaDoc getMethod() {
162         return method;
163     }
164
165     /**
166      * Getter for property encType.
167      *
168      * @return Value of property encType.
169      */

170     public String JavaDoc getEncType() {
171         return encType;
172     }
173
174     /**
175      * Getter for property attributesText.
176      *
177      * @return Value of property attributesText.
178      */

179     public String JavaDoc getAttributesText() {
180         return attributesText;
181     }
182
183     /**
184      * Getter for property attributes.
185      *
186      * @return Value of property attributes.
187      */

188     public Map JavaDoc getAttributes() {
189         return attributes;
190     }
191
192     /**
193      * Getter for property action.
194      *
195      * @return Value of property action.
196      */

197     public String JavaDoc getAction() {
198         return action;
199     }
200
201 }
Popular Tags