01: package ru.emdev.EmForge.web.converter;
02:
03: import java.util.Date;
04:
05: import javax.faces.component.UIComponent;
06: import javax.faces.context.FacesContext;
07: import javax.faces.convert.Converter;
08:
09: import org.apache.commons.lang.StringUtils;
10:
11: public class DateTimeNullSafeConverter implements Converter {
12:
13: public Object getAsObject(FacesContext i_context,
14: UIComponent i_component, String i_str) {
15: if (StringUtils.isEmpty(i_str)) {
16: return null;
17: }
18:
19: if ("null".equals(i_str)) {
20: return null;
21: }
22:
23: // convert i_str to long
24: Long lValue = Long.parseLong(i_str);
25:
26: return new Date(lValue);
27: }
28:
29: public String getAsString(FacesContext i_context,
30: UIComponent i_component, Object i_date) {
31: if (i_date == null) {
32: return "";
33: }
34:
35: if (i_date instanceof String) {
36: return (String) i_date;
37: }
38:
39: Date date = (Date) i_date;
40: return String.valueOf(date.getTime());
41: }
42:
43: }
|