1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 * Renders timepicker element.</p>
28 * Format supported by this component are:-
29 * <table border="1">
30 * <tr>
31 * <td>Format</td>
32 * <td>Description</td>
33 * </tr>
34 * <tr>
35 * <td>#HH</td>
36 * <td>Display hour in two digit format</td>
37 * </tr>
38 * <tr>
39 * <td>#H</td>
40 * <td>Try to display hour in one digit format, if cannot use 2 digits</td>
41 * </tr>
42 * <tr>
43 * <td>#hh</td>
44 * <td>Display hour in two digit format</td>
45 * </tr>
46 * <tr>
47 * <td>#h</td>
48 * <td>Try to display hour in one digit format, if cannot use 2 digits</td>
49 * </tr>
50 * <tr>
51 * <td>#mm</td>
52 * <td>Display minutes in 2 digits format</td>
53 * </tr>
54 * <tr>
55 * <td>#m</td>
56 * <td>Try to display minutes in 2 digits fomrat, if cannot use 2 digits</td>
57 * </tr>
58 * </table>
59 *
60 * <!-- END SNIPPET: javadoc -->
61 *
62 *
63 * <pre>
64 * <!-- START SNIPPET: example -->
65 *
66 * <s:timepicker label="Show Time" name="showTime" value="05:00" format="#hh:#mm" />
67 *
68 * <s:timepicker label="Dinner Time" name="dinnerTime" format="#hh-#mm" />
69 *
70 * <!-- END SNIPPET: example -->
71 * </pre>
72 *
73 * @version $Date: 2006-09-30 01:38:02 -0400 (Sat, 30 Sep 2006) $ $Id: TimePicker.java 451544 2006-09-30 05:38:02Z mrdon $
74 */
75 public class TimePicker extends TextField {
76
77 final public static String TEMPLATE = "timepicker";
78
79 protected String format;
80 protected String templatePath;
81 protected String templateCssPath;
82 protected String timeIconPath;
83 protected String size;
84
85 public TimePicker(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
86 super(stack, request, response);
87 }
88
89 protected void evaluateExtraParams() {
90 super.evaluateExtraParams();
91
92 if (format != null) {
93 addParameter("format", findString(format));
94 }
95 if (timeIconPath != null) {
96 addParameter("timeIconPath", timeIconPath);
97 }
98 if (templatePath != null) {
99 addParameter("templatePath", templatePath);
100 }
101 if (templateCssPath != null) {
102 addParameter("templateCssPath", templateCssPath);
103 }
104 if (size != null) {
105 addParameter("size", findValue(size, Integer.class));
106 }
107 }
108
109 protected String getDefaultTemplate() {
110 return TEMPLATE;
111 }
112
113 /***
114 * The format to use for time field.
115 * @s.tagattribute required="false" type="String" default="Dateformat specified by language preset (%Y/%m/%d for en)"
116 */
117 public void setFormat(String format) {
118 this.format = format;
119 }
120
121 /***
122 * The time picker icon path
123 * @s.tagattribute required="false" type="String" default="/struts/dojo/struts/widgets/dateIcon.gif"
124 */
125 public void setTimeIconPath(String timeIconPath) {
126 this.timeIconPath = timeIconPath;
127 }
128
129 /***
130 * The time picker template path.
131 * @s.tagattribute required="false" type="String"
132 */
133 public void setTemplatePath(String templatePath) {
134 this.templatePath = templatePath;
135 }
136
137 /***
138 * The time picker template css path.
139 * @s.tagattribute required="false" type="String"
140 */
141 public void setTemplateCssPath(String templateCssPath) {
142 this.templateCssPath = templateCssPath;
143 }
144
145 /***
146 * The time picker text field size.
147 * @s.tagattribute required="false" type="String"
148 */
149 public void setSize(String size) {
150 this.size = size;
151 }
152
153 }