1 Reply Latest reply on Nov 13, 2009 10:59 PM by spersch

    Problem with h:selectOneListBox and Dates

    spersch

      Hi Together,


      I have a Date field in a entityclass and I want to fill it. When I create a h:inputText field or rich:calendar all is working fine when I type for example following date: 13.09.2009 . The Datefield in the entity was filled correctly and all is working great.


      Now I need a dropdown to select the date and I create a h:selectOneListBox with s:selectItems which gets a list of dates that can be chosen. Now i get a FacesMessage with validation failed.


      Code - XHTML:




      <h:outputLabel for="date" value="Datum:" />
      <!-- WORKS
          <rich:calendar locale="de/DE" popup="true" value="#{feed.date}" showApplyButton="false" datePattern="dd.MM.yyyy" id="date" />
      WORKS -->
      
      <!-- DOESN'T WORKS -->
          <h:selectOneListbox value="#{feed.date}" id="date" size="1">
              <s:selectItems var="fdate" value="#{feedbean.listOfDates}" label="#{fdate.date}" />
          </h:selectOneListbox>
      <!-- /DOESN'T WORKS -->
      
      <!-- WORKS
          <h:inputText value="#{feed.date}" id="date" />
      WORKS -->



      Code - method for dates:


      public List<Date> getListOfDates() {
          final ArrayList<Date> result = new ArrayList<Date>();
          final Calendar todayCopy = Calendar.getInstance();
          int i = 1;
          while (i <= 5) {
              todayCopy.add(Calendar.DATE, +1);
              final int dow = todayCopy.get(Calendar.DAY_OF_WEEK);
              if (Calendar.SATURDAY != dow && Calendar.SUNDAY != dow) {
                  result.add(todayCopy.getTime());
                  ++i;
              }
          }
          return result;
      }
      



      I don't get an exception, only facesMessage that the validation failed for the datefield.


      Thank you for help,
      best regards
      Steffen