2 Replies Latest reply on Nov 25, 2009 9:34 AM by Sullitaz Sullitaz

    selectOneMenu with dynamic values

    Sullitaz Sullitaz Newbie
      Hello !
      I am a newbie and I got a problem.
      I would like to generate a selectOneMenu like the period list from google adwords in order to display some statistics data from my database; that means a list of options like this:
      1) a custom period --> when selected, we got 2 calendars in order to set the "from date" and the "To date".
      2) Today
      3) Yesterday
      5) Last 7 days
      ...

      I got a period table in my database (id, value, label, start date, end date) -->
      (1,"P1","Custom",null,null)
      (2,"P2","Today",null,null)
      (3,"P3","Yesterday",null,null)
      ...

      The problem I have is I need to calculate the correct period depending on the selected period.
      So, when the form is submitted, I can execute a function in order to calculate the period, set variables, and refresh my statistics datatable like this
      i(selectedPeriod == "P2")
      {
      start = cal.getTime();
      end = cal.getTime();
      }
      else if (selectedPeriod == "P3")
      {
      end = cal.getTime();
      cal.add(Calendar.DATE, -1);
      start = cal.getTime();
      }
      ...
      I wonder if there is another more elegant method to do that?
      Is it possible to calculate the end date before populating the selectItems?
      Thanks in advance for your help