I have the next data table in my page:
<t:dataTable value="#{bean.listOfPersons}" var="current">
<t:column>
<t:outputText value="#{current.birthdate}">
<f:converter pattern="dd/mm/yyyy HH:mm" type="date"/>
</t:outputText>
</t:column>
</t:dataTable>
Person
is an object I created, and one of it's properties is birthdate.
Now I wish to display the details of many persons in this <t:dateTable>
, including the birthdate. As you can see, I choose to display the birthdate in dd/mm/yyyy HH:mm
pattern, so I can see the time if known. Now, the problem is that some of the birthdates doesn't have a time (only date), and when the time is null
in java.util.Date
, the time is automatic 00:00. How can I display the birthdate in short pattern if time is unknown (only date), and the regular pattern when I know the time (date and time)?
What happens now:
17/3/1994 5:56
1/1/1991 00:00
12/2/1990 17:53
21/12/2012 00:00
What I want to see:
17/3/1994 5:56
1/1/1991
12/2/1990 17:53
21/12/2012
Short pattern when time is unknown.
This is what I'm writing in the page.xhtml:
<t:outputText value="#{bean.date}">
<f:converter convertetId="myconverter" pattern="[some pattern]" timeZone="America/Chicago" type="date">
</t:outputText>
This is the converter:
public class MyConverter extends DateTimeConverter
{
@Override
public String getAsString (FacesContext faces, UIComponent comp, Object obj)
{
this.setTimeZone(null);
String result = super.getAsString(faces, comp, obj);
// My converter here...
return result;
}
@Override
public void setTimeZone(TimeZone tz)
{
// Always setting my own time zone, no matter what.
super.setTimeZone(TimeZone.getTimeZone("America/Chicago"));
}
}
Now, as you can see, I'm always setting the time zone myself on getAsString
because
somehow now the f:converter doesn't recognize it's attributes... know why?