View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbTextAreaTag.java,v 1.26 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.26 $
4    * $Date: 2006/01/13 13:38:51 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib;
25  
26  import javax.servlet.jsp.JspException;
27  
28  
29  
30  /***
31   * <p>
32   * This tag renders a HTML TextArea - Element
33   * </p>
34   * this tag renders a dabase-datadriven textArea, which is an active element -
35   * the user can change data
36   *
37   * @author Joachim Peer
38   */
39  public class DbTextAreaTag extends AbstractDbBaseInputTag
40     implements javax.servlet.jsp.tagext.TryCatchFinally {
41     /*** DOCUMENT ME! */
42     protected String renderBody;
43  
44     /*** DOCUMENT ME! */
45     protected String wrap;
46  
47     /***
48      * Sets the renderBody
49      *
50      * @param renderBody The renderBody to set
51      */
52     public void setRenderBody(String renderBody) {
53        this.renderBody = renderBody;
54     }
55  
56  
57     /***
58      * Gets the renderBody
59      *
60      * @return Returns a String
61      */
62     public String getRenderBody() {
63        return renderBody;
64     }
65  
66  
67     /***
68      * DOCUMENT ME!
69      *
70      * @param wrap DOCUMENT ME!
71      */
72     public void setWrap(String wrap) {
73        this.wrap = wrap;
74     }
75  
76  
77     /***
78      * DOCUMENT ME!
79      *
80      * @return DOCUMENT ME!
81      */
82     public String getWrap() {
83        return wrap;
84     }
85  
86  
87     /***
88      * DOCUMENT ME!
89      *
90      * @return DOCUMENT ME!
91      *
92      * @throws javax.servlet.jsp.JspException DOCUMENT ME!
93      * @throws JspException DOCUMENT ME!
94      */
95     public int doEndTag() throws javax.servlet.jsp.JspException {
96        try {
97           if ("true".equals(renderBody) && (bodyContent != null)) {
98              bodyContent.writeOut(bodyContent.getEnclosingWriter());
99              bodyContent.clearBody(); // workaround for duplicate rows in JRun 3.1
100          }
101 
102          pageContext.getOut()
103                     .write("</textArea>");
104 
105          // Writes out the old field value
106          writeOutSpecialValues();
107 
108          // For generation Javascript Validation.  Need all original and modified fields name
109          getParentForm()
110             .addChildName(getName(), getFormFieldName());
111       } catch (java.io.IOException ioe) {
112          throw new JspException("IO Error: " + ioe.getMessage());
113       }
114 
115       return EVAL_PAGE;
116    }
117 
118 
119    /***
120     * DOCUMENT ME!
121     */
122    public void doFinally() {
123       wrap       = null;
124       renderBody = null;
125       super.doFinally();
126    }
127 
128 
129    /***
130     * DOCUMENT ME!
131     *
132     * @return DOCUMENT ME!
133     *
134     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
135     * @throws JspException DOCUMENT ME!
136     */
137    public int doStartTag() throws javax.servlet.jsp.JspException {
138       super.doStartTag();
139 
140       StringBuffer tagBuf = new StringBuffer("<textarea ");
141 
142       tagBuf.append(prepareName());
143 
144       if (wrap != null) {
145          tagBuf.append(" wrap=\"");
146          tagBuf.append(wrap);
147          tagBuf.append("\"");
148       }
149 
150       if (getCols() != null) {
151          tagBuf.append(" cols=\"");
152          tagBuf.append(getCols());
153          tagBuf.append("\"");
154       }
155 
156       if (getRows() != null) {
157          tagBuf.append(" rows=\"");
158          tagBuf.append(getRows());
159          tagBuf.append("\"");
160       }
161 
162       tagBuf.append(prepareKeys());
163       tagBuf.append(prepareStyles());
164       tagBuf.append(prepareEventHandlers());
165       tagBuf.append(">");
166 
167       /* If the overrideValue attribute has been set, use its value instead of the one
168       retrieved from the database.  This mechanism can be used to set an initial default
169       value for a given field. */
170       if (!"true".equals(renderBody)) {
171          tagBuf.append(escapeHTML(getFormFieldValue()));
172       }
173 
174       try {
175          pageContext.getOut()
176                     .write(tagBuf.toString());
177       } catch (java.io.IOException e) {
178          throw new JspException("IO Error: " + e.getMessage());
179       }
180 
181       if (!"true".equals(renderBody)) {
182          return EVAL_BODY_BUFFERED;
183       } else {
184          return SKIP_BODY;
185       }
186    }
187 }