KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > tags > DateTag


1 package org.roller.presentation.tags;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.apache.struts.Globals;
9 import org.apache.struts.action.ActionMapping;
10 import org.apache.struts.util.RequestUtils;
11
12 /**
13  * Struts-based date field tag that wraps Matt Kruze's JavaScript data chooser.
14  * @jsp.tag name="Date"
15  */

16 public class DateTag extends TagSupport JavaDoc
17 {
18     static final long serialVersionUID = 1485100916981692535L;
19     
20     // Unique key prefix keeps us from colliding with other tags and user data
21
public static final String JavaDoc KEY_PREFIX = "ZZZ_DATETAG_ZZZ";
22
23     private String JavaDoc property = null;
24     private String JavaDoc dateFormat = null;
25     private Boolean JavaDoc readOnly = Boolean.FALSE;
26
27     private static Log mLogger =
28         LogFactory.getFactory().getInstance(DateTag.class);
29
30     /**
31      * Renders date field by calling a JSP page.
32      */

33     public int doStartTag() throws JspException JavaDoc
34     {
35
36         // Get form name
37
ActionMapping mapping =
38             (ActionMapping) pageContext.getRequest().getAttribute(
39                 Globals.MAPPING_KEY);
40         String JavaDoc formName = mapping.getName();
41
42         // Get value of form field
43
Object JavaDoc value =
44             RequestUtils.lookup(pageContext, formName, property, null);
45         if (value == null)
46             value = "";
47
48         // put variables into request scope for view page
49
pageContext.getRequest().setAttribute(
50             KEY_PREFIX + "_formName",
51             formName);
52         pageContext.getRequest().setAttribute(
53             KEY_PREFIX + "_property",
54             property);
55         pageContext.getRequest().setAttribute(
56             KEY_PREFIX + "_dateFormat",
57             dateFormat);
58         pageContext.getRequest().setAttribute(
59             KEY_PREFIX + "_readOnly",
60             readOnly);
61         pageContext.getRequest().setAttribute(KEY_PREFIX + "_value", value);
62
63         // dispatch to view page
64
try
65         {
66             pageContext.include("/tags/date.jsp");
67         }
68         catch (Exception JavaDoc e)
69         {
70             // can't handle this here
71
throw new JspException JavaDoc("ERROR including date.jsp");
72         }
73
74         // Don't evaluate content of tag, just continue processing this page
75
return (SKIP_BODY);
76     }
77
78     /**
79      * Date format string to be used.
80      *
81      * @jsp.attribute required="true" rtexprvalue="true" type="java.lang.String"
82      */

83     public String JavaDoc getDateFormat()
84     {
85         return dateFormat;
86     }
87
88     /**
89      * Name of form property represented.
90      * @jsp.attribute required="true" rtexprvalue="true" type="java.lang.String"
91      */

92     public String JavaDoc getProperty()
93     {
94         return property;
95     }
96
97     /**
98      * True if field should be readOnly.
99      * @jsp.attribute required="false" rtexprvalue="true" type="java.lang.Boolean"
100      */

101     public Boolean JavaDoc getReadOnly()
102     {
103         return readOnly;
104     }
105
106     public void setDateFormat(String JavaDoc dateFormat)
107     {
108         this.dateFormat = dateFormat;
109     }
110
111     public void setProperty(String JavaDoc property)
112     {
113         this.property = property;
114     }
115
116     public void setReadOnly(Boolean JavaDoc readOnly)
117     {
118         this.readOnly = readOnly;
119     }
120
121 }
122
Popular Tags