1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jsf.core;
20
21 import java.util.TimeZone;
22
23 import javax.el.ELException;
24 import javax.faces.FacesException;
25 import javax.faces.convert.Converter;
26 import javax.faces.convert.DateTimeConverter;
27 import javax.faces.view.facelets.ConverterConfig;
28 import javax.faces.view.facelets.ConverterHandler;
29 import javax.faces.view.facelets.FaceletContext;
30 import javax.faces.view.facelets.FaceletException;
31 import javax.faces.view.facelets.MetaRuleset;
32 import javax.faces.view.facelets.TagAttribute;
33 import javax.faces.view.facelets.TagAttributeException;
34
35 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
36 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
37
38
39
40
41
42
43
44
45
46
47 @JSFFaceletTag(
48 name = "f:convertDateTime",
49 bodyContent = "empty",
50 converterClass="javax.faces.convert.DateTimeConverter")
51 public final class ConvertDateTimeHandler extends ConverterHandler
52 {
53
54 private final TagAttribute dateStyle;
55
56 private final TagAttribute locale;
57
58 private final TagAttribute pattern;
59
60 private final TagAttribute timeStyle;
61
62 private final TagAttribute timeZone;
63
64 private final TagAttribute type;
65
66
67
68
69 public ConvertDateTimeHandler(ConverterConfig config)
70 {
71 super(config);
72 this.dateStyle = this.getAttribute("dateStyle");
73 this.locale = this.getAttribute("locale");
74 this.pattern = this.getAttribute("pattern");
75 this.timeStyle = this.getAttribute("timeStyle");
76 this.timeZone = this.getAttribute("timeZone");
77 this.type = this.getAttribute("type");
78 }
79
80
81
82
83
84
85
86 protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException
87 {
88 return ctx.getFacesContext().getApplication().createConverter(DateTimeConverter.CONVERTER_ID);
89
90 }
91
92
93
94
95
96
97 public void setAttributes(FaceletContext ctx, Object obj)
98 {
99 DateTimeConverter c = (DateTimeConverter) obj;
100 if (this.locale != null)
101 {
102 c.setLocale(ComponentSupport.getLocale(ctx, this.locale));
103 }
104 if (this.pattern != null)
105 {
106 c.setPattern(this.pattern.getValue(ctx));
107 }
108 else
109 {
110 if (this.type != null)
111 {
112 c.setType(this.type.getValue(ctx));
113 }
114 if (this.dateStyle != null)
115 {
116 c.setDateStyle(this.dateStyle.getValue(ctx));
117 }
118 if (this.timeStyle != null)
119 {
120 c.setTimeStyle(this.timeStyle.getValue(ctx));
121 }
122 }
123
124 if (this.timeZone != null)
125 {
126 Object t = this.timeZone.getObject(ctx);
127 if (t != null)
128 {
129 if (t instanceof TimeZone)
130 {
131 c.setTimeZone((TimeZone) t);
132 }
133 else if (t instanceof String)
134 {
135 TimeZone tz = TimeZone.getTimeZone((String) t);
136 c.setTimeZone(tz);
137 }
138 else
139 {
140 throw new TagAttributeException(this.tag, this.timeZone,
141 "Illegal TimeZone, must evaluate to either a java.util.TimeZone or String, is type: "
142 + t.getClass());
143 }
144 }
145 }
146 }
147
148 protected MetaRuleset createMetaRuleset(Class type)
149 {
150 return super.createMetaRuleset(type).ignoreAll();
151 }
152 }