Skip to content

Instantly share code, notes, and snippets.

@prule
Created May 31, 2013 04:23
Show Gist options
  • Select an option

  • Save prule/5682930 to your computer and use it in GitHub Desktop.

Select an option

Save prule/5682930 to your computer and use it in GitHub Desktop.
JSF converter for joda-time DateMidnight
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