如何在JSF中显示不同模式的日期t:dataTable? [英] How to display a date in different patterns in JSF t:dataTable?
问题描述
我的页面中有下一个数据表:
< t:dataTable value =#{bean.listOfPersons }var =current>
< t:column>
< t:outputText value =#{current.birthdate}>
< f:转换器模式=dd / mm / yyyy HH:mmtype =date/>
< / t:outputText>
< / t:column>
< / t:dataTable>
Person
是我创建的对象,其中一个属性是生日。
现在我想在这个< t:dateTable>
中显示许多人的详细信息,包括出生日期。如您所见,我选择在 dd / mm / yyyy HH:mm
模式中显示出生日期,所以我可以看到时间。现在,问题是有些生日没有时间(只有日期),而在 java.util中的时间是
,时间是自动00:00。如果时间不明(只有日期),以及当我知道时间(日期和时间)时的常规模式,我如何以短时间显示出生日期? null
。日期
发生什么现在:
17/3/1994 5:56
1/1/1991 00:00
12/2/1990 17:53
21/12/2012 00:00
什么我想看看:
17/3/1994 5:56
1/1/1991
12/2/1990 17:53
21/12/2012
时间短的模式是未知的。
这是我在page.xhtml中写的:
< t:outputText value =#{bean.date}>
< f:converter convertetId =myconverterpattern =[some pattern]timeZone =America / Chicagotype =date>
< / t:outputText>
这是转换器:
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);
//我的转换器在这里...
return result;
}
@Override
public void setTimeZone(TimeZone tz)
{
//始终设置自己的时区,无论如何。
super.setTimeZone(TimeZone.getTimeZone(America / Chicago));
}
}
现在,你可以看到,我总是因为
不知何故现在f:转换器不能识别它的属性...知道为什么?
getAsString
b 使用ocpsoft使用 PrettyTime 库。它具有不错的用于JSF的预构建转换器,同时支持不同的区域设置。 p>
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?
Use PrettyTime library by ocpsoft. It has a nice pre-built converter for JSF, also with support for different Locales.
这篇关于如何在JSF中显示不同模式的日期t:dataTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!