KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > DbDateFieldTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbDateFieldTag.java,v 1.33 2004/08/18 12:26:06 hkollmann Exp $
3  * $Revision: 1.33 $
4  * $Date: 2004/08/18 12:26:06 $
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.http.HttpServletRequest JavaDoc;
27 import javax.servlet.jsp.JspException JavaDoc;
28
29
30
31 /**
32  * <p>
33  * This tag renders a HTML TextArea - Element
34  * </p>
35  * this tag renders a dabase-datadriven textArea, which is an active element -
36  * the user can change data
37  *
38  * @author Joachim Peer
39  */

40 public class DbDateFieldTag extends DbBaseInputTag
41    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
42    /** Holds value of property jsCalendarDateFormat. */
43    private String JavaDoc jsCalendarDateFormat;
44
45    /** Holds value of property useJsCalendar. */
46    private String JavaDoc useJsCalendar;
47
48    /**
49     * Setter for property jsCalendarDateFormat.
50     *
51     * @param jsCalendarDateFormat New value of property jsCalendarDateFormat.
52     */

53    public void setJsCalendarDateFormat(String JavaDoc jsCalendarDateFormat) {
54       this.jsCalendarDateFormat = jsCalendarDateFormat;
55    }
56
57
58    /**
59     * Getter for property jsCalendarDateFormat.
60     *
61     * @return Value of property jsCalendarDateFormat.
62     */

63    public String JavaDoc getJsCalendarDateFormat() {
64       return jsCalendarDateFormat;
65    }
66
67
68    /**
69     * Setter for property useJsCalendar.
70     *
71     * @param useJsCalendar New value of property useJsCalendar.
72     */

73    public void setUseJsCalendar(String JavaDoc useJsCalendar) {
74       this.useJsCalendar = useJsCalendar;
75    }
76
77
78    /**
79     * Getter for property useJsCalendar.
80     *
81     * @return Value of property useJsCalendar.
82     */

83    public String JavaDoc getUseJsCalendar() {
84       return useJsCalendar;
85    }
86
87
88    /**
89     * @see javax.servlet.jsp.tagext.TryCatchFinally#doCatch(java.lang.Throwable)
90     */

91    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
92       throw t;
93    }
94
95
96    /**
97     * DOCUMENT ME!
98     *
99     * @return DOCUMENT ME!
100     *
101     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
102     * @throws JspException DOCUMENT ME!
103     */

104    public int doEndTag() throws JspException JavaDoc {
105       HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) this.pageContext
106                                    .getRequest();
107
108       try {
109          StringBuffer JavaDoc tagBuf = new StringBuffer JavaDoc("<input ");
110          tagBuf.append(prepareType());
111          tagBuf.append(prepareName());
112          tagBuf.append(prepareValue());
113          tagBuf.append(prepareSize());
114          tagBuf.append(prepareKeys());
115          tagBuf.append(prepareStyles());
116          tagBuf.append(prepareEventHandlers());
117          tagBuf.append("/>");
118
119          // if property useJSCalendar is set to 'true' we will now add a little
120
// image that can be clicked to popup a small JavaScript Calendar
121
// written by Robert W. Husted to edit the field:
122
if (!hasHiddenSet() && ("true".equals(this.getUseJsCalendar()))) {
123             tagBuf.append(" <a HREF=\"javascript:doNothing()\" ")
124                   .append(" onclick=\"");
125
126             // if date format is not explicitely set for this calendar,
127
// use date format for this form field.
128
if ((jsCalendarDateFormat == null)
129                       && (getFormatter() instanceof java.text.SimpleDateFormat JavaDoc)) {
130                java.text.SimpleDateFormat JavaDoc mysdf = (java.text.SimpleDateFormat JavaDoc) getFormatter();
131                jsCalendarDateFormat = mysdf.toPattern();
132
133                // 2 digit date format pattern is 'dd' in Java, 'DD' in
134
// JavaScript calendar
135
if (jsCalendarDateFormat.indexOf("dd") >= 0) {
136                   jsCalendarDateFormat = jsCalendarDateFormat.replace('d', 'D');
137                }
138             }
139
140             if (jsCalendarDateFormat != null) // JS Date Format set ?
141
{
142                tagBuf.append("calDateFormat='" + jsCalendarDateFormat + "';");
143             }
144
145             tagBuf.append("setDateField(document.dbform['")
146                   .append(getFormFieldName())
147                   .append("']);")
148                   .append(" top.newWin = window.open('")
149                   .append(request.getContextPath())
150                   .append("/dbformslib/jscal/calendar.html','cal','width=270,height=280')\">")
151                   .append("<img SRC=\"")
152                   .append(request.getContextPath())
153                   .append("/dbformslib/jscal/calendar.gif\" ") //width=\"16\" height=\"16\"
154

155                   .append(" border=\"0\" alt=\"Click on the Calendar to activate the Pop-Up Calendar Window.\">")
156                   .append("</img>")
157                   .append("</a>");
158          }
159
160          // For generation Javascript Validation. Need all original and modified fields name
161
getParentForm()
162             .addChildName(getName(), getFormFieldName());
163
164          pageContext.getOut()
165                     .write(tagBuf.toString());
166
167          // Writes out the old field value
168
writeOutSpecialValues();
169       } catch (java.io.IOException JavaDoc ioe) {
170          throw new JspException JavaDoc("IO Error: " + ioe.getMessage());
171       }
172
173       return EVAL_PAGE;
174    }
175
176
177    /**
178     * DOCUMENT ME!
179     */

180    public void doFinally() {
181       super.doFinally();
182    }
183
184
185    /**
186     * DOCUMENT ME!
187     *
188     * @return DOCUMENT ME!
189     *
190     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
191     */

192    public int doStartTag() throws JspException JavaDoc {
193       super.doStartTag();
194
195       return SKIP_BODY;
196    }
197 }
198
Popular Tags