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 | 0 | super(config); |
72 | 0 | this.dateStyle = this.getAttribute("dateStyle"); |
73 | 0 | this.locale = this.getAttribute("locale"); |
74 | 0 | this.pattern = this.getAttribute("pattern"); |
75 | 0 | this.timeStyle = this.getAttribute("timeStyle"); |
76 | 0 | this.timeZone = this.getAttribute("timeZone"); |
77 | 0 | this.type = this.getAttribute("type"); |
78 | 0 | } |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException |
87 | |
{ |
88 | 0 | 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 | 0 | DateTimeConverter c = (DateTimeConverter) obj; |
100 | 0 | if (this.locale != null) |
101 | |
{ |
102 | 0 | c.setLocale(ComponentSupport.getLocale(ctx, this.locale)); |
103 | |
} |
104 | 0 | if (this.pattern != null) |
105 | |
{ |
106 | 0 | c.setPattern(this.pattern.getValue(ctx)); |
107 | |
} |
108 | |
else |
109 | |
{ |
110 | 0 | if (this.type != null) |
111 | |
{ |
112 | 0 | c.setType(this.type.getValue(ctx)); |
113 | |
} |
114 | 0 | if (this.dateStyle != null) |
115 | |
{ |
116 | 0 | c.setDateStyle(this.dateStyle.getValue(ctx)); |
117 | |
} |
118 | 0 | if (this.timeStyle != null) |
119 | |
{ |
120 | 0 | c.setTimeStyle(this.timeStyle.getValue(ctx)); |
121 | |
} |
122 | |
} |
123 | |
|
124 | 0 | if (this.timeZone != null) |
125 | |
{ |
126 | 0 | Object t = this.timeZone.getObject(ctx); |
127 | 0 | if (t != null) |
128 | |
{ |
129 | 0 | if (t instanceof TimeZone) |
130 | |
{ |
131 | 0 | c.setTimeZone((TimeZone) t); |
132 | |
} |
133 | 0 | else if (t instanceof String) |
134 | |
{ |
135 | 0 | TimeZone tz = TimeZone.getTimeZone((String) t); |
136 | 0 | c.setTimeZone(tz); |
137 | 0 | } |
138 | |
else |
139 | |
{ |
140 | 0 | 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 | 0 | } |
147 | |
|
148 | |
protected MetaRuleset createMetaRuleset(Class type) |
149 | |
{ |
150 | 0 | return super.createMetaRuleset(type).ignoreAll(); |
151 | |
} |
152 | |
} |