tags:

views:

1070

answers:

1

Hi,

I have a <h:selectOneMenu> that has <f:selectItems> with CategoryHistory objects loaded in it. I only show the Date date field as itemLabel. That works but I want to format the date: I created a converter that extends javax.faces.convert.DateTimeConverter and change the fields in the constructor. But my dates only show in default format :(

DateAndTimeConverter.java

import javax.faces.bean.ManagedBean;
import javax.faces.convert.Converter;
import javax.faces.convert.DateTimeConverter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value = "dateAndTimeconverter")
@ManagedBean
public class DateAndTimeConverter extends DateTimeConverter implements Converter {

 public DateAndTimeConverter(){  
  this.setDateStyle("short");
 }

xhtml

 <h:selectOneMenu valueChangeListener="#{admin.categoryHistoryListener}"
    onchange="submit()" value="#{admin.categoryHistory.id}" converter="#{dateAndTimeconverter}">       
  <f:selectItems value="#{admin.categoryHistories}" var="n"
     itemValue="#{n.id}" itemLabel="#{n.date}">
  </f:selectItems>
 </h:selectOneMenu>

It also doesn't work when I try:

<h:selectOneMenu valueChangeListener="#{admin.categoryHistoryListener}"
    onchange="submit()" value="#{admin.categoryHistory.id}">
  <f:converter converterId="dateAndTimeconverter"/>       
  <f:selectItems value="#{admin.categoryHistories}" var="n"
     itemValue="#{n.id}" itemLabel="#{n.date}">
  </f:selectItems>
</h:selectOneMenu>

CategoryHistory Has a Date date, and Long id +...

Thank you

+1  A: 

Unfortunately, the JSF converters only applies on the input value, not on the input label.

You'll need to solve this other ways. E.g. a getter which uses SimpleDateFormat to format the date.

BalusC
Ouch that hurts... Thanks anyway:)
Michael Bavin