Prettytime —- JSF Converter for Joda Time

Splash Forums PrettyTime Users Prettytime —- JSF Converter for Joda Time

This topic contains 1 reply, has 2 voices, and was last updated by  Lincoln Baxter III 9 years, 5 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #18658


    The standard JSF converter for Prettytime only support java.util.Date objects. The code below is an extension to that supporting Joda time the new standard for date time etc in future release of JDK.

    package com.effectivcrm.core.prettytime;
    import java.util.Date;
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.inject.Named;
    import org.joda.time.DateTime;
    import com.ocpsoft.pretty.time.web.jsf.PrettyTimeConverter;

    public class PrettyJodaTimeConverter extends PrettyTimeConverter {
    private static final long serialVersionUID = -7092244860259925929L;
    public String getAsString(final FacesContext context,
    final UIComponent comp, final Object value) {
    if (value instanceof DateTime) {
    Date date = ((DateTime) value).toDate();
    return super.getAsString(context, comp, date);
    return super.getAsString(context, comp, value);

    This is how I use it in the JSF XHTML, My converter is a Spring bean.

    <h:outputText value="#{target.createdDate}" converter="#{prettyJodaTimeConverter}" />


    Awesome! Thanks for sharing :)

Viewing 2 posts - 1 through 2 (of 2 total)

The forum ‘PrettyTime Users’ is closed to new topics and replies.

Comments are closed.