1 Reply Latest reply on Nov 9, 2014 4:10 PM by Tom Hain

    Date Items in rich:pickList not converted

    Tom Hain Newbie

      I make use of the RichFaces component rich:pickList to provide a list of Date objects which can be selected

      When the data gets validated the JSF page shows a validation error: "Validation Error: Value is not valid". I know, the Date Object is somehow not converted. But I don't know why? First I tried setting the attribute dateConverter:

      converter="#{javax.faces.convert.DateTimeConverter}"

      This didn't work. Afterwards, I added the following statement:

      <f:convertDateTime pattern="MM/dd/yyyy" />

      Didn't solve the issue either.

      Btw: What is the difference of both ?

       

      Please find below the whole source code:

      XHTML

       

      !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" 
         xmlns:h="http://java.sun.com/jsf/html" 
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:ui="http://java.sun.com/jsf/facelets" 
         xmlns:a4j="http://richfaces.org/a4j"
         xmlns:rich="http://richfaces.org/rich">
      
         <ui:composition template="/templates/template.xhtml">
              <ui:define name="body">
                   <h:form prependId="false">
                        <rich:pickList id = "datePL" 
                             value="#{richBean.listOfNewDates}"  
                             sourceCaption="All Dates" 
                             targetCaption="New Dates">
                                  <f:selectItems value="#{richBean.listOfDates}"
                                       var="_item" itemValue="#{_item}" itemLabel="#{_item}" />
                                       <f:convertDateTime pattern="MM/dd/yyyy" />
                        </rich:pickList>
                        <a4j:commandButton action="#{richBean.printListOfDates()}" value="Print"/>
                             <rich:notifyMessages stayTime="2000" nonblocking="true" />
                   </h:form>
              </ui:define>
         </ui:composition>
      </html>

       

      Managed Bean:

       

      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.Calendar;
      import java.util.Date;
      import java.util.Iterator;
      import java.util.List;
      import javax.annotation.PostConstruct;
      import javax.faces.bean.SessionScoped;
      import javax.inject.Named;
      
      @Named("richBean")
      @SessionScoped
      public class RichBean implements Serializable {
      
         private static final long serialVersionUID = -2403138958014741653L;
         private List<Date> listOfDates;
         private List<Date> listOfNewDates;
      
         @PostConstruct
         public void init() {
        setListOfDates(new ArrayList<Date>());
         Calendar cal = Calendar.getInstance();
        getListOfDates().add(cal.getTime());
        cal.add(Calendar.DATE, 1);
        getListOfDates().add(cal.getTime());
        cal.add(Calendar.DATE, 2);
        getListOfDates().add(cal.getTime());
         }
      
         /**
        * @return the listOfDates
        */
         public List<Date> getListOfDates() {
         return listOfDates;
         }
      
         /**
        * @return the listOfNewDates
        */
         public List<Date> getListOfNewDates() {
         return listOfNewDates;
         }
      
         /**
        * @param listOfNewDates the listOfNewDates to set
        */
         public void setListOfNewDates(List<Date> listOfNewDates) {
         this.listOfNewDates = listOfNewDates;
         }
      
         public void printListOfDates() {
         for (Iterator<Date> it = listOfNewDates.iterator(); it.hasNext();) {
         System.out.println("Neues Datum = " + it.toString());
         }
         }
      
         /**
        * @param listOfDates the listOfDates to set
        */
         public void setListOfDates(List<Date> listOfDates) {
         this.listOfDates = listOfDates;
         }
      }