Created
May 31, 2013 04:23
-
-
Save prule/5682930 to your computer and use it in GitHub Desktop.
JSF converter for joda-time DateMidnight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.apache.commons.lang.StringUtils; | |
| import org.joda.time.DateMidnight; | |
| import org.joda.time.format.DateTimeFormat; | |
| import org.springframework.stereotype.Component; | |
| import javax.faces.component.UIComponent; | |
| import javax.faces.context.FacesContext; | |
| import javax.faces.convert.Converter; | |
| @Component | |
| public class DateMidnightConverter implements Converter { | |
| @Override | |
| public Object getAsObject(FacesContext context, UIComponent component, String value) { | |
| return DateTimeFormat.forPattern("dd/MMM/yyyy").parseDateTime(value).toDateMidnight(); | |
| } | |
| @Override | |
| public String getAsString(FacesContext context, UIComponent component, Object value) { | |
| if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) return ""; | |
| return DateTimeFormat.forPattern("dd/MMM/yyyy").print((DateMidnight)value); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment