Marko
Marko

Reputation: 159

how to format jsf 2.0 <f:selectItems/> with date value from List

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'?

Upvotes: 1

Views: 2985

Answers (3)

Brian Leathem
Brian Leathem

Reputation: 4639

Use a backing bean method to return a list of SelectItems, populated from your list of allowed Dates. Format the date as you like when you create the list of SelectItems.

Upvotes: 1

Wayne
Wayne

Reputation: 149

This should do it.

<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>

you can use pattern="" to do almost anything with the date.

Upvotes: 1

Inv3r53
Inv3r53

Reputation: 2969

Not sure if you can do the conversion in xhtml using jsf. One way is to use SimpleDateFormat class in your bean and format values in bean itself and add it to the list avaliableIntervals

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

Upvotes: 1

Related Questions