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 5 years, 1 month ago.

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

    Frursioni
    Member

    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;

    @Named
    public class PrettyJodaTimeConverter extends PrettyTimeConverter {
    private static final long serialVersionUID = -7092244860259925929L;
    @Override
    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);
    }
    else{
    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}" />

    #22872

    Awesome! Thanks for sharing :)

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

You must be logged in to reply to this topic.

Comments are closed.