View Javadoc

1   /*
2    * $Id: DatePicker.java 451544 2006-09-30 05:38:02Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.components;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import com.opensymphony.xwork2.util.ValueStack;
24  
25  /***
26   * <!-- START SNIPPET: javadoc -->
27   *
28   * Renders datepicker element.</p>
29   * Format supported by this component are:-
30   * <table border="1">
31   *   <tr>
32   *   	<td>Format</td>
33   *    	<td>Description</td>
34   *   </tr>
35   *   <tr>
36   *   	<td>#dd</td>
37   *   	<td>Display day in two digits format</td>
38   *   </tr>	
39   *   <tr>
40   *   	<td>#d</td>
41   *   	<td>Try to display day in one digit format, if cannot use 2 digit format</td>
42   *   </tr>
43   *   <tr>
44   *   	<td>#MM</td>
45   *      <td>Display month in two digits format</td>
46   *   </tr>
47   *   <tr>
48   *   	<td>#M</td>
49   *   	<td>Try to display month in one digits format, if cannot use 2 digit format</td>
50   *   </tr>
51   *   <tr>
52   *   	<td>#yyyy</td>
53   *      <td>Display year in four digits format</td>
54   *   </tr>
55   *   <tr>
56   *   	<td>#yy</td>
57   *      <td>Display the last two digits of the yaer</td>
58   *   </tr>
59   *   <tr>
60   *   	<td>#y</td>
61   *      <td>Display the last digits of the year</td>
62   *   </tr>
63   * </table>
64   *
65   * <p/>
66   *
67   * <!-- END SNIPPET: javadoc -->
68   *
69   * <b>Examples</b>
70   *
71   * <pre>
72   * <!-- START SNIPPET: expl1 -->
73   *
74   * Example 1:
75   *     &lt;s:datepicker name="order.date" label="Order Date" /&gt;
76   * Example 2:
77   *     &lt;s:datepicker name="delivery.date" label="Delivery Date" format="#yyyy-#MM-#dd"  /&gt;
78   *     
79   * <!-- END SNIPPET: expl1 -->
80   * </pre>
81   * <p/>
82   *
83   * <!-- START SNIPPET: expldesc2 -->
84   *
85   * The css could be changed by using the following :-
86   *
87   * <!-- END SNIPPET: expldesc2 -->
88   * 
89   * <pre>
90   * <!-- START SNIPPET: expl2 -->
91   * 
92   * &lt;s:datepicker name="birthday" label="Birthday" templateCss="...." /&gt;
93   * 
94   * <!-- END SNIPPET: expl2 -->
95   * </pre>
96   *
97   * @s.tag name="datepicker" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.DatePickerTag"
98   * description="Render datepicker"
99   */
100 public class DatePicker extends TextField {
101 
102     final public static String TEMPLATE = "datepicker";
103 
104     protected String format;
105     protected String dateIconPath;
106     protected String templatePath;
107     protected String templateCssPath;
108     protected String size;
109 
110     public DatePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
111         super(stack, request, response);
112     }
113 
114     protected String getDefaultTemplate() {
115         return TEMPLATE;
116     }
117 
118     public void evaluateParams() {
119         super.evaluateParams();
120 
121         if (format != null) {
122             addParameter("format", findString(format));
123         }
124         if (dateIconPath != null) {
125         	addParameter("dateIconPath", dateIconPath);
126         }
127         if (templatePath != null) {
128         	addParameter("templatePath", templatePath);
129         }
130         if (templateCssPath != null) {
131         	addParameter("templateCssPath", templateCssPath);
132         }
133         if (size != null) {
134         	addParameter("size", findValue(size, Integer.class));
135         }
136     }
137 
138     /***
139      * The format to use for date field.
140      * @s.tagattribute required="false" type="String" default="Dateformat specified by language preset (%Y/%m/%d for en)"
141      */
142     public void setFormat(String format) {
143         this.format = format;
144     }
145     
146     /***
147      * The date picker icon path
148      * @s.tagattribute required="false" type="String" default="/struts/dojo/struts/widgets/dateIcon.gif"
149      */
150     public void setDateIconPath(String dateIconPath) {
151     	this.dateIconPath = dateIconPath;
152     }
153     
154     /***
155      * The datepicker template path.
156      * @s.tagattribute required="false" type="String"
157      */
158     public void setTemplatePath(String templatePath) {
159     	this.templatePath = templatePath;
160     }
161     
162     /***
163      * The datepicker template css path.
164      * @s.tagattribute required="false" type="String"
165      */
166     public void setTemplateCssPath(String templateCssPath) {
167     	this.templateCssPath = templateCssPath;
168     }
169     
170     /***
171      * The datepicker text field size.
172      * @s.tagattribute required="false" type="String"
173      */
174     public void setSize(String size) {
175     	this.size = size;
176     }
177 }