2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.shale.clay.convert;
22
23 import java.util.TimeZone;
24
25 import javax.faces.component.UIComponent;
26 import javax.faces.context.FacesContext;
27 import javax.faces.convert.Converter;
28
29 /***
30 * <p>Converts a time zone id literal string into the
31 * <code>TimeZone</code> and back to a string.</p>
32 */
33 public class TimeZoneConverter implements Converter {
34
35 /***
36 * <p>Converts the string zone ID into a TimeZone object.</p>
37 *
38 * @param facesContext jsf faces context
39 * @param component converter assigned
40 * @param value to be converterd
41 * @return strong typed value
42 */
43 public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
44
45 TimeZone zone = TimeZone.getTimeZone(value);
46 return zone;
47 }
48
49 /***
50 * <p>Converts a TimeZone object into the string zone id.</p>
51 *
52 * @param facesContext jsf faces context
53 * @param component converter assigned
54 * @param value to be converterd
55 * @return string represention of the value
56 */
57 public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
58
59 TimeZone zone = (TimeZone) value;
60 if (value != null) {
61 return zone.getID();
62 }
63
64 return null;
65 }
66
67 }