1

Im using jsf 2.0 to develop app where user has to select (using radio button) a date from the list of possible choices. List of dates is a managed bean property of type List< java.util.Date>. Im using facelets

<h:selectOneRadio value="#{banner_backing.selectedInterval}" border="1" layout="pageDirection">
        <f:selectItems value="#{banner_backing.avaliableIntervals}" var="interval">                    
                </f:selectItems>
</h:selectOneRadio>

to display radio buttons.

Here is my question: how to format selectItems label and value in a patter other then default (Fri May 28 00:00:00 CEST 2010), like 'HH:mm:ss dd/MM/yyyy'?

4

3 回答 3

1

不确定是否可以使用 jsf 在 xhtml 中进行转换。一种方法是在 bean 中使用SimpleDateFormat类并在 bean 本身中格式化值并将其添加到列表中avaliableIntervals

http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html

于 2010-05-30T13:34:06.443 回答
1

使用支持 bean 方法返回一个列表SelectItems,从您的允许列表中填充Dates。创建列表时,根据需要格式化日期SelectItems

于 2010-06-05T22:22:50.823 回答
1

这应该这样做。

<h:selectOneRadio value="#{banner_backing.selectedInterval}" border="1" layout="pageDirection">
     <f:convertDateTime type="date" dateStyle="short"/>
     <f:selectItems value="#{banner_backing.avaliableIntervals}" var="interval"/>                    
</h:selectOneRadio>

您可以使用 pattern="" 对日期执行几乎任何操作。

于 2011-03-23T13:54:22.433 回答