KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > tags > DateTag


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.ui.core.tags;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.struts.Globals;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.util.RequestUtils;
28
29 /**
30  * Struts-based date field tag that wraps Matt Kruze's JavaScript data chooser.
31  * @jsp.tag name="Date"
32  */

33 public class DateTag extends TagSupport JavaDoc {
34     static final long serialVersionUID = 1485100916981692535L;
35     
36     // Unique key prefix keeps us from colliding with other tags and user data
37
public static final String JavaDoc KEY_PREFIX = "ZZZ_DATETAG_ZZZ";
38     
39     private String JavaDoc property = null;
40     private String JavaDoc dateFormat = null;
41     private Boolean JavaDoc readOnly = Boolean.FALSE;
42     private String JavaDoc formName = null;
43     
44     private static Log mLogger =
45             LogFactory.getFactory().getInstance(DateTag.class);
46     
47     /**
48      * Renders date field by calling a JSP page.
49      */

50     public int doStartTag() throws JspException JavaDoc {
51         
52         // Get form name
53
ActionMapping mapping =
54                 (ActionMapping) pageContext.getRequest().getAttribute(
55                 Globals.MAPPING_KEY);
56         if (formName == null) {
57             formName = mapping.getName();
58         }
59         
60         // Get value of form field
61
Object JavaDoc value =
62                 RequestUtils.lookup(pageContext, formName, property, null);
63         if (value == null)
64             value = "";
65         
66         // put variables into request scope for view page
67
pageContext.getRequest().setAttribute(
68                 KEY_PREFIX + "_formName",
69                 formName);
70         pageContext.getRequest().setAttribute(
71                 KEY_PREFIX + "_property",
72                 property);
73         pageContext.getRequest().setAttribute(
74                 KEY_PREFIX + "_dateFormat",
75                 dateFormat);
76         pageContext.getRequest().setAttribute(
77                 KEY_PREFIX + "_readOnly",
78                 readOnly);
79         pageContext.getRequest().setAttribute(KEY_PREFIX + "_value", value);
80         
81         // dispatch to view page
82
try {
83             pageContext.include("/roller-ui/widgets/date.jsp");
84         } catch (Exception JavaDoc e) {
85             // can't handle this here
86
throw new JspException JavaDoc("ERROR including date.jsp");
87         }
88         
89         // Don't evaluate content of tag, just continue processing this page
90
return (SKIP_BODY);
91     }
92     
93     /**
94      * Date format string to be used.
95      *
96      * @jsp.attribute required="true" rtexprvalue="true" type="java.lang.String"
97      */

98     public String JavaDoc getDateFormat() {
99         return dateFormat;
100     }
101     
102     public void setDateFormat(String JavaDoc dateFormat) {
103         this.dateFormat = dateFormat;
104     }
105
106     /**
107      * Name of form property represented.
108      * @jsp.attribute required="true" rtexprvalue="true" type="java.lang.String"
109      */

110     public String JavaDoc getProperty() {
111         return property;
112     }
113     
114     public void setProperty(String JavaDoc property) {
115         this.property = property;
116     }
117     
118     /**
119      * True if field should be readOnly.
120      * @jsp.attribute required="false" rtexprvalue="true" type="java.lang.Boolean"
121      */

122     public Boolean JavaDoc getReadOnly() {
123         return readOnly;
124     }
125         
126     public void setReadOnly(Boolean JavaDoc readOnly) {
127         this.readOnly = readOnly;
128     }
129     
130     /**
131      * Form name, only needed when more than one form on page.
132      * @jsp.attribute required="false" rtexprvalue="true" type="java.lang.String"
133      */

134     public String JavaDoc getFormName() {
135         return formName;
136     }
137         
138     public void setFormName(String JavaDoc formName) {
139         this.formName = formName;
140     }
141     
142 }
143
Popular Tags