org.apache.turbine.util
Class DateSelector

java.lang.Object
  extended byorg.apache.turbine.util.DateSelector

public class DateSelector
extends java.lang.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 534527 2007-05-02 16:10:59Z tv $
Author:
Jeffrey D. Brekke, Jon S. Stevens, Leon Atkinson

Field Summary
static java.lang.String DAY_SUFFIX
          Suffix for day parameter.
static java.lang.String DEFAULT_PREFIX
          Prefix for date names.
static java.lang.String MONTH_SUFFIX
          Suffix for month parameter.
static java.lang.String YEAR_SUFFIX
          Suffix for year parameter.
 
Constructor Summary
DateSelector()
          Constructor defaults to current date and uses the default prefix: DateSelector.DEFAULT
DateSelector(java.lang.String selName)
          Constructor defaults to current date.
DateSelector(java.lang.String selName, java.util.Calendar useDate)
          Constructor, uses the date set in a calendar that has been already passed in (with the date set correctly).
 
Method Summary
 org.apache.ecs.ElementContainer ecsOutput()
           
static org.apache.ecs.html.Select getDaySelector(java.lang.String name)
          Return a day selector.
static org.apache.ecs.html.Select getDaySelector(java.lang.String name, java.util.Calendar now)
          Return a day selector.
static org.apache.ecs.html.Select getMonthSelector(java.lang.String name)
          Return a month selector.
static org.apache.ecs.html.Select getMonthSelector(java.lang.String name, java.util.Calendar now)
          Return a month selector.
 java.lang.String getSelName()
          Get the selector name prefix.
static org.apache.ecs.html.Select getYearSelector(java.lang.String name)
          Return a year selector.
static org.apache.ecs.html.Select getYearSelector(java.lang.String name, java.util.Calendar now)
          Return a year selector.
static org.apache.ecs.html.Select getYearSelector(java.lang.String name, int firstYear, int lastYear, int selectedYear)
          Return a year selector.
 java.lang.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(java.lang.String onChange)
          Adds the onChange to all of <SELECT> tags.
 void setSelName(java.lang.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)
          Select the day to be selected if the showDays(false) behavior is used.
 java.lang.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 java.lang.String DEFAULT_PREFIX
Prefix for date names.

See Also:
Constant Field Values

DAY_SUFFIX

public static final java.lang.String DAY_SUFFIX
Suffix for day parameter.

See Also:
Constant Field Values

MONTH_SUFFIX

public static final java.lang.String MONTH_SUFFIX
Suffix for month parameter.

See Also:
Constant Field Values

YEAR_SUFFIX

public static final java.lang.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(java.lang.String selName,
                    java.util.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.

DateSelector

public DateSelector(java.lang.String selName)
Constructor defaults to current date.

Parameters:
selName - A String with the selector name.
Method Detail

setOnChange

public DateSelector setOnChange(java.lang.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.

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(java.lang.String selName)
Set the selector name prefix. Individual getMonth, getDay, getYear static methods will not use this setting.


getSelName

public java.lang.String getSelName()
Get the selector name prefix.

Returns:
A String with the select name prefix.

getMonthSelector

public static org.apache.ecs.html.Select getMonthSelector(java.lang.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(java.lang.String name,
                                                          java.util.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(java.lang.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(java.lang.String name,
                                                        java.util.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(java.lang.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(java.lang.String name,
                                                         java.util.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(java.lang.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)
Select the day to be selected if the showDays(false) behavior is used. Individual getMonth, getDay, getYear static methods will not use this setting.

Returns:
A DateSelector (self).

output

public java.lang.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: 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 java.lang.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: 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.

ecsOutput

public org.apache.ecs.ElementContainer ecsOutput()


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.