org.apache.turbine.util

## Class DateSelector

- java.lang.Object
- - org.apache.turbine.util.DateSelector

-     public class DateSelector
      extends Object

  DateSelector is a utility class to handle the creation of a set of date popup menus. The code is broken into a set of static methods for quick and easy access to the individual select objects:

        ElementContainer ec dateSelect = new ElementContainer();
        String myName = "mydate";
        ec.addElement(DateSelector.getMonthSelector(myName));
        ec.addElement(DateSelector.getDaySelector(myName));
        ec.addElement(DateSelector.getYearSelector(myName));

  There are also methods which will use attributes to build a complete month,day,year selector:

        DateSelector ds = new DateSelector(myName);
        dateSelect = ds.ecsOutput();

  The above element container would use the onChange setting and may hide the selected day if set via showDays().
  Version:
    $Id: DateSelector.java 1706239 2015-10-01 13:18:35Z tv $
  Author:
    Jeffrey D. Brekke, Jon S. Stevens, Leon Atkinson

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DAY_SUFFIX` Suffix for day parameter.
    `static String` | `DEFAULT_PREFIX` Prefix for date names.
    `static String` | `MONTH_SUFFIX` Suffix for month parameter.
    `static String` | `YEAR_SUFFIX` Suffix for year parameter.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DateSelector()` Constructor defaults to current date and uses the default prefix: DateSelector.DEFAULT
    `DateSelector(String selName)` Constructor defaults to current date.
    `DateSelector(String selName, Calendar useDate)` Constructor, uses the date set in a calendar that has been already passed in (with the date set correctly).

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.apache.ecs.ElementContainer` | `ecsOutput()` Return an ECS container with the month, day, and year select objects inside.
    `static org.apache.ecs.html.Select` | `getDaySelector(String name)` Return a day selector.
    `static org.apache.ecs.html.Select` | `getDaySelector(String name, Calendar now)` Return a day selector.
    `static org.apache.ecs.html.Select` | `getMonthSelector(String name)` Return a month selector.
    `static org.apache.ecs.html.Select` | `getMonthSelector(String name, Calendar now)` Return a month selector.
    `String` | `getSelName()` Get the selector name prefix.
    `static org.apache.ecs.html.Select` | `getYearSelector(String name)` Return a year selector.
    `static org.apache.ecs.html.Select` | `getYearSelector(String name, Calendar now)` Return a year selector.
    `static org.apache.ecs.html.Select` | `getYearSelector(String name, int firstYear, int lastYear, int selectedYear)` Return a year selector.
    `String` | `output()` Used to build the popupmenu in HTML.
    `DateSelector` | `setDay(int day)` Select the day to be selected if the showDays(false) behavior is used.
    `DateSelector` | `setOnChange(String onChange)` Adds the onChange to all of <SELECT> tags.
    `void` | `setSelName(String selName)` Set the selector name prefix.
    `DateSelector` | `setShowDay(boolean show)` Whether or not to show the days as a popup menu.
    `boolean` | `setYear(int firstYear, int lastYear, int selectedYear)` Set a year range to be displayed
    `String` | `toString()` Used to build the popupmenu in HTML.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PREFIX

          public static final String DEFAULT_PREFIX

      Prefix for date names.
      See Also:
        Constant Field Values

    - #### DAY_SUFFIX

          public static final String DAY_SUFFIX

      Suffix for day parameter.
      See Also:
        Constant Field Values

    - #### MONTH_SUFFIX

          public static final String MONTH_SUFFIX

      Suffix for month parameter.
      See Also:
        Constant Field Values

    - #### YEAR_SUFFIX

          public static final String YEAR_SUFFIX

      Suffix for year parameter.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DateSelector

          public DateSelector()

      Constructor defaults to current date and uses the default prefix:

          DateSelector.DEFAULT

    - #### DateSelector

          public DateSelector(String selName)

      Constructor defaults to current date.
      Parameters:
        `selName` - A String with the selector name.

    - #### DateSelector

          public DateSelector(String selName,
                      Calendar useDate)

      Constructor, uses the date set in a calendar that has been already passed in (with the date set correctly).
      Parameters:
        `selName` - A String with the selector name.
        `useDate` - A Calendar with a date.

  - ### Method Detail

    - #### setOnChange

          public DateSelector setOnChange(String onChange)

      Adds the onChange to all of <SELECT> tags. This is limited to one function for all three popups and is only used when the output() methods are used. Individual getMonth, getDay, getYear static methods will not use this setting.
      Parameters:
        `onChange` - A String to use for onChange attribute. If null, then nothing will be set.
      Returns:
        A DateSelector (self).

    - #### setDay

          public DateSelector setDay(int day)

      Select the day to be selected if the showDays(false) behavior is used. Individual getMonth, getDay, getYear static methods will not use this setting.
      Parameters:
        `day` - The day.
      Returns:
        A DateSelector (self).

    - #### setShowDay

          public DateSelector setShowDay(boolean show)

      Whether or not to show the days as a popup menu. The days will be a hidden parameter and the value set with setDay is used. Individual getMonth, getDay, getYear static methods will not use this setting.
      Parameters:
        `show` - True if the day should be shown.
      Returns:
        A DateSelector (self).

    - #### setSelName

          public void setSelName(String selName)

      Set the selector name prefix. Individual getMonth, getDay, getYear static methods will not use this setting.
      Parameters:
        `selName` - A String with the select name prefix.

    - #### getSelName

          public String getSelName()

      Get the selector name prefix.
      Returns:
        A String with the select name prefix.

    - #### getMonthSelector

          public static org.apache.ecs.html.Select getMonthSelector(String name)

      Return a month selector.
      Parameters:
        `name` - The name to use for the selected month.
      Returns:
        A select object with all the months.

    - #### getMonthSelector

          public static org.apache.ecs.html.Select getMonthSelector(String name,
                                                    Calendar now)

      Return a month selector. Note: The values of the month placed into the select list are the month integers starting at 0 (ie: if the user selects February, the selected value will be 1).
      Parameters:
        `name` - The name to use for the selected month.
        `now` - Calendar to start with.
      Returns:
        A select object with all the months.

    - #### getDaySelector

          public static org.apache.ecs.html.Select getDaySelector(String name)

      Return a day selector.
      Parameters:
        `name` - The name to use for the selected day.
      Returns:
        A select object with all the days in a month.

    - #### getDaySelector

          public static org.apache.ecs.html.Select getDaySelector(String name,
                                                  Calendar now)

      Return a day selector.
      Parameters:
        `name` - The name to use for the selected day.
        `now` - Calendar to start with.
      Returns:
        A select object with all the days in a month.

    - #### getYearSelector

          public static org.apache.ecs.html.Select getYearSelector(String name)

      Return a year selector.
      Parameters:
        `name` - The name to use for the selected year.
      Returns:
        A select object with all the years starting five years from now and five years before this year.

    - #### getYearSelector

          public static org.apache.ecs.html.Select getYearSelector(String name,
                                                   Calendar now)

      Return a year selector.
      Parameters:
        `name` - The name to use for the selected year.
        `now` - Calendar to start with.
      Returns:
        A select object with all the years starting five years from now and five years before this year.

    - #### getYearSelector

          public static org.apache.ecs.html.Select getYearSelector(String name,
                                                   int firstYear,
                                                   int lastYear,
                                                   int selectedYear)

      Return a year selector.
      Parameters:
        `name` - The name to use for the selected year.
        `firstYear` - the first (earliest) year in the selector.
        `lastYear` - the last (latest) year in the selector.
        `selectedYear` - the year initially selected in the Select html.
      Returns:
        A select object with all the years from firstyear to lastyear..

    - #### setYear

          public boolean setYear(int firstYear,
                        int lastYear,
                        int selectedYear)

      Set a year range to be displayed
      Parameters:
        `firstYear` - start of year range
        `lastYear` - end of year range
        `selectedYear` - entry to select
      Returns:
        true if the range settings are valid

    - #### output

          public String output()

      Used to build the popupmenu in HTML. The properties set in the object are used to generate the correct HTML. The selName attribute is used to seed the names of the select lists. The names will be generated as follows:
      - selName + "_month"
      - selName + "_day"
      - selName + "_year"
      If onChange was set it is also used in the generation of the output. The output HTML will list the select lists in the following order: month day year.
      Returns:
        A String with the correct HTML for the date selector.

    - #### toString

          public String toString()

      Used to build the popupmenu in HTML. The properties set in the object are used to generate the correct HTML. The selName attribute is used to seed the names of the select lists. The names will be generated as follows:
      - selName + "_month"
      - selName + "_day"
      - selName + "_year"
      The output HTML will list the select lists in the following order: month day year.
      Overrides:
        `toString` in class `Object`
      Returns:
        A String with the correct HTML for the date selector.

    - #### ecsOutput

          public org.apache.ecs.ElementContainer ecsOutput()

      Return an ECS container with the month, day, and year select objects inside.
      Returns:
        An ECS container.

Copyright © 2000-2015 The Apache Software Foundation. All Rights Reserved.