Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 以良好的方式打印org.joda.time.Period对象_Jsf 2_Jodatime_Omnifaces - Fatal编程技术网

Jsf 2 以良好的方式打印org.joda.time.Period对象

Jsf 2 以良好的方式打印org.joda.time.Period对象,jsf-2,jodatime,omnifaces,Jsf 2,Jodatime,Omnifaces,我有一个包含org.joda.time.Minutes字段的实体。我想在我的组件中使用该字段作为标签: <h:selectOneMenu value="#{manager.spec}" converter="omnifaces.SelectItemsIndexConverter"> <f:selectItem itemLabel="#{msg.choose_one}" /> <f:selectItems value="#{allSpe

我有一个包含
org.joda.time.Minutes
字段的实体。我想在我的
组件中使用该字段作为标签:

<h:selectOneMenu value="#{manager.spec}"
        converter="omnifaces.SelectItemsIndexConverter">
    <f:selectItem itemLabel="#{msg.choose_one}" />
    <f:selectItems value="#{allSpecs}" var="spec" 
        itemLabel="#{f.print(spec.timeout.toStandardDuration().toPeriod())}" />
</h:selectOneMenu>
这将使用用户所在地区的文字打印,例如
5分钟
1小时10分钟
3个月、2小时5分钟

我的问题很简单:有没有更好的方法?我为格式化程序尝试了一个简单的Producer方法,但由于
PeriodFormatter
不公开无参数构造函数,因此这不会与CDI一起运行


额外问题:这是否是omnifaces日期函数的一个很好的补充?

在ZEEF我们正在使用它。添加到OmniFaces会很困难,因为这需要对轮子进行大量的重新改造,因为我们不希望有任何依赖关系。@BalusC Mhh,我必须再看一次。据我所见,唯一的“jsf原生”方法是附加一个转换器。但我从未对
itemlab
这样做过,也不知道该怎么做。另外,转换器只接受
Date
对象。从一段时间内得到它们不会很漂亮(没有双关语的意思)。
@Named("f")
@RequestScoped
public class UserPeriodFormatter {
    private PeriodFormatter printer;

    @PostConstruct
    public void init() {
        printer = PeriodFormat.wordBased(Faces.getLocale());
    }

    public String print(ReadablePeriod period) {
        return printer.print(period);
    }
}