01: package org.obe.worklist;
02:
03: import org.obe.util.DateUtilities;
04:
05: import javax.faces.convert.Converter;
06: import javax.faces.context.FacesContext;
07: import javax.faces.component.UIComponent;
08: import java.io.Serializable;
09: import java.text.ParseException;
10: import java.util.Date;
11:
12: /**
13: * Converts objects to/from non-null strings.
14: *
15: * @author Adrian Price
16: */
17: public class DateConverter implements Converter, Serializable {
18: private static final long serialVersionUID = 545113577714637932L;
19:
20: public DateConverter() {
21: }
22:
23: public Object getAsObject(FacesContext context,
24: UIComponent component, String value) {
25:
26: try {
27: return value == null || value.equals(" ") ? null
28: : DateUtilities.getInstance().parse(value);
29: } catch (ParseException e) {
30: return null;
31: }
32: }
33:
34: public String getAsString(FacesContext context,
35: UIComponent component, Object value) {
36:
37: String s = DateUtilities.getInstance().format((Date) value);
38: return s == null || s.length() == 0 ? " " : s;
39: }
40: }
|