001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.jsp.tags;
021:
022: import com.salmonllc.html.HtmlComponent;
023:
024: import com.salmonllc.jsp.JspForm;
025: import com.salmonllc.jsp.TagWriter;
026:
027: import com.salmonllc.util.MessageLog;
028:
029: /////////////////////////
030: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/tags/FormTag.java $
031: //$Author: Srufle $
032: //$Revision: 9 $
033: //$Modtime: 6/11/04 2:09p $
034: /////////////////////////
035: import java.io.IOException;
036: import javax.servlet.jsp.JspException;
037: import javax.servlet.jsp.JspWriter;
038:
039: /**
040: * This is a tag used to create a form tag.
041: */
042: public class FormTag extends ContainerTag {
043: private String _action;
044: private String _autoscroll;
045: private String _content;
046: private String _encType;
047: private String _hiddenFields;
048: private String _method;
049: private String _onReset;
050: private String _onSubmit;
051: private String _target;
052:
053: /**
054: * Sets the action for this form (The URL invoked when the form is posted)
055: *
056: * @param action
057: */
058: public void setAction(String action) {
059: _action = action;
060: }
061:
062: /**
063: * Sets whether the form should auto scroll
064: *
065: * @param string
066: */
067: public void setAutoscroll(String string) {
068: _autoscroll = string;
069: }
070:
071: /**
072: * Sets the mime type encoding of the data sent "application/x-www-form-urlencoded" (the default), is usually used if the METHOD attribute has the value POST. "multipart/form-data" is used when the form contains a file upload element (INPUT TYPE="FILE").
073: *
074: * @param encType
075: */
076: public void setEnctype(String encType) {
077: _encType = encType;
078: }
079:
080: /**
081: * Sets the method for this form (GET or POST)
082: *
083: * @param method
084: */
085: public void setMethod(String method) {
086: _method = method;
087: }
088:
089: /**
090: * Sets the javascript code that executes if the user resets the form
091: *
092: * @param onReset
093: */
094: public void setOnreset(String onReset) {
095: _onReset = onReset;
096: }
097:
098: /**
099: * Sets the javascript code that executes if the user submits the form
100: *
101: * @param onSubmit
102: */
103: public void setOnsubmit(String onSubmit) {
104: _onSubmit = onSubmit;
105: }
106:
107: /**
108: * Returns the type of DreamWeaver conversion that this tag uses.
109: *
110: * @return
111: */
112: public int getTagConvertType() {
113: return CONV_CUSTOM;
114: }
115:
116: /**
117: * Sets the window that will display the results of the submit
118: *
119: * @param target
120: */
121: public void setTarget(String target) {
122: _target = target;
123: }
124:
125: /**
126: * This method creates the JspForm used by the tag.
127: *
128: * @return
129: */
130: public HtmlComponent createComponent() {
131: JspForm form = new JspForm(getName(), getHelper()
132: .getController());
133:
134: if (!BaseTagHelper.isEmpty(_action)) {
135: form.setAction(_action);
136: }
137:
138: if (!BaseTagHelper.isEmpty(_method)) {
139: form.setMethod(_method);
140: }
141:
142: if (!BaseTagHelper.isEmpty(_onReset)) {
143: form.setOnReset(_onReset);
144: }
145:
146: if (!BaseTagHelper.isEmpty(_onSubmit)) {
147: form.setOnSubmit(_onSubmit);
148: }
149:
150: if (!BaseTagHelper.isEmpty(_target)) {
151: form.setTarget(_target);
152: }
153:
154: if (!BaseTagHelper.isEmpty(_encType)) {
155: form.setEncType(_encType);
156: }
157:
158: if (!BaseTagHelper.isEmpty(getVisible())) {
159: form
160: .setVisible(BaseTagHelper
161: .stringToBoolean(getVisible()));
162: }
163:
164: if (!BaseTagHelper.isEmpty(getEnabled())) {
165: form
166: .setEnabled(BaseTagHelper
167: .stringToBoolean(getEnabled()));
168: }
169:
170: if (!BaseTagHelper.isEmpty(_autoscroll)) {
171: form.setAutoScrollEnabled(BaseTagHelper
172: .stringToBoolean(_autoscroll));
173: }
174:
175: return form;
176: }
177:
178: /**
179: * This is part of the JSP tag specification
180: *
181: * @return
182: *
183: * @throws JspException
184: */
185: public int doEndTag() throws JspException {
186: getHelper().getTagContext().setRefIndexPrinted(false);
187:
188: return super .doEndTag();
189: }
190:
191: /**
192: * This is part of the JSP tag specification
193: *
194: * @return
195: *
196: * @throws JspException
197: */
198: public int doStartTag() throws JspException {
199: getHelper().getTagContext().setRefIndexPrinted(false);
200:
201: return super .doStartTag();
202: }
203:
204: /**
205: * This method generates the html used by the tag.
206: *
207: * @param p
208: *
209: * @throws IOException
210: */
211: public void generateComponentHTML(JspWriter p) throws IOException {
212: JspForm form = (JspForm) getHelper().getController()
213: .getComponent(getName());
214:
215: if (form == null) {
216: return;
217: }
218:
219: TagWriter w = getTagWriter();
220: w.setWriter(p);
221:
222: form.generateHTML(w, _content);
223: }
224:
225: /**
226: * For Tags that require multiple passes to render their Html, this method should be implemented. It wll be called for each mode until it returns false. Also, this method is responsible for storing the results of the tags nested within it. Once the method returns false, the generateComponentHtml method will be called and here, the stored data from the nested tags should be sent to the output
227: * stream.
228: *
229: * @return
230: */
231: public boolean incrementMode() {
232: try {
233: _content = getBodyContentData(true);
234:
235: if ((_hiddenFields != null) && (_hiddenFields.length() > 0)) {
236: _content = _hiddenFields + _content;
237: }
238: } catch (Exception e) {
239: MessageLog.writeErrorMessage("incrementMode()", e, this );
240: }
241:
242: return false;
243: }
244:
245: /**
246: * Initializes the tag
247: */
248: public void initMode() {
249: _content = null;
250: _hiddenFields = generateFormHiddenFieldHtml();
251: }
252:
253: /**
254: * Part of the tag library specification. Clears all resources used by the tag.
255: */
256: public void release() {
257: super.release();
258: _action = null;
259: _method = null;
260: _onReset = null;
261: _onSubmit = null;
262: _target = null;
263: _encType = null;
264: _content = null;
265: _hiddenFields = null;
266: _autoscroll = null;
267: }
268: }
|