While reading the docs and the hint that DateSelector should be updated to use
ecs I changed DateSelector to use ecs and allow the user to get each
individual select list. The old interface is maintained and new methods were
added. Implementation is all done in ecs. Any problems or if the patch doesn't
get through, let me know about some other way to contribute the code.
PS: First time contributor, so I may not know the "preferred customs"...
-- CUT --
Index: DateSelector.java
===================================================================
RCS file:
/products/cvs/turbine/turbine/src/java/org/apache/turbine/util/DateSelector.java,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 DateSelector.java
61a62,63
> import org.apache.ecs.html.*;
> import org.apache.ecs.*;
68,69c70
< * This code was ported from leon's php3 code. It should probably be
< * re-written to use ECS.
---
> * This code was ported from leon's php3 code.
70a72,75
> * Modifications added to use ecs and allow for each element to have
> * its own name and you can get each select list indivually.
> *
> * @author Jeffrey D. Brekke <a
href="mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]</a>
81c86
< private String[] months = null;
---
> private static final String[] monthName = new
DateFormatSymbols().getMonths();
85a91,92
>
>
94a102
>
130a139
>
132c141,142
< Used to build the popupmenu HTML
---
> @param name the name to use for the selected month
> @return A select object with all the months
134c144
< public String output()
---
> public Select getMonthSelector(String name)
136,150c146,147
< months = new DateFormatSymbols().getMonths();
< StringBuffer out = new StringBuffer ( 256 );
< if ( this.useDate == null )
< {
< this.useDate.setTime ( new Date() );
< }
< int month = this.useDate.get( Calendar.MONTH );
< int day = this.useDate.get( Calendar.DAY_OF_MONTH );
< int year = this.useDate.get( Calendar.YEAR );
<
< // Month
< if ( onChangeSet )
< out.append ( "\n<SELECT NAME=\"" + selName + "Month\"
onChange=\"" + onChange + "\">\n" );
< else
< out.append ( "\n<SELECT NAME=\"" + selName + "Month" + "\">\n"
);
---
> return(getMonthSelector(name, Calendar.getInstance()));
> }
152c149,162
< for ( int currMonth = 0; currMonth <= 11; currMonth++ )
---
> /**
> Note: This will set the correct month value ( ie: 1 based ),
> but constructing a calendar requires the months to start at zero,
not one.
> @param name the name to use for the selected month
> @param Calendar to start with.
> @return A select object with all the months
> */
> public Select getMonthSelector(String name, Calendar now)
> {
> Select monthSelect = new Select().setName(name);
> if (onChangeSet)
> monthSelect.setOnChange(onChange);
>
> for (int curMonth = 0;curMonth <= 11; curMonth++)
154,157c164,167
< out.append ( "<OPTION VALUE=\"" );
< out.append ( currMonth );
< out.append ( "\"" );
< if ( month == currMonth )
---
> Option o = new Option();
> o.addElement(monthName[curMonth]);
> o.setValue(curMonth+1);
> if ((now.get(Calendar.MONTH)) == curMonth)
159c169
< out.append (" SELECTED" );
---
> o.setSelected(true);
161c171
< out.append ( ">" + months[currMonth] + "\n" );
---
> monthSelect.addElement(o);
163c173,174
< out.append ("</SELECT>\n");
---
> return(monthSelect);
> }
165,171c176,196
< // Day
< if ( this.showDays == false )
< {
< if ( this.setDay > 0 )
< out.append ( "<FONT SIZE=\"-1\" FACE=\"Helvetica, Arial\">"
+ this.setDay + "</FONT>" + "<INPUT TYPE=\"hidden\" NAME=\"" + selName +
"Day\" VALUE=\"" + this.setDay + "\">\n" );
< }
< else
---
> /**
> @param name the name to use for the selected day
> @return A select object with all the days in a month
> */
> public Select getDaySelector(String name)
> {
> return(getDaySelector(name, Calendar.getInstance()));
> }
>
> /**
> @param name the name to use for the selected day
> @param now Calendar to start with.
> @return A select object with all the days in a month
> */
> public Select getDaySelector(String name, Calendar now)
> {
> Select daySelect = new Select().setName(name);
> if (onChangeSet)
> daySelect.setOnChange(onChange);
>
> for(int currentDay=1; currentDay <= 31; currentDay++)
173,178c198,200
< if ( onChangeSet )
< out.append ( "\n<SELECT NAME=\"" + selName + "Day\"
onChange=\"" + onChange + "\">\n" );
< else
< out.append ( "\n<SELECT NAME=\"" + selName + "Day\">\n" );
<
< for ( int currDay = 1; currDay <= 31; currDay++ )
---
> Option o = new Option();
> o.addElement(Integer.toString(currentDay));
> if (now.get(Calendar.DAY_OF_MONTH) == currentDay)
180,187c202
< out.append ( "<OPTION VALUE=\"" );
< out.append ( currDay );
< out.append ( "\"" );
< if ( day == currDay )
< {
< out.append (" SELECTED" );
< }
< out.append ( ">" + currDay + "\n" );
---
> o.setSelected(true);
189c204
< out.append ("</SELECT>\n");
---
> daySelect.addElement(o);
191,198c206,230
<
< // Year
< if ( onChangeSet )
< out.append ( "\n<SELECT NAME=\"" + selName + "Year\"
onChange=\"" + onChange + "\">\n" );
< else
< out.append ( "\n<SELECT NAME=\"" + selName + "Year\">\n" );
<
< for ( int currYear = year - 5; currYear <= year + 5; currYear++ )
---
> return(daySelect);
> }
>
> /**
> @param name the name to use for the selected year
> @return A select object with all the years starting five years from now
and five years before this year.
> */
> public Select getYearSelector(String name)
> {
> return(getYearSelector(name, Calendar.getInstance()));
> }
>
> /**
> @param name the name to use for the selected year
> @param now Calendar to start with.
> @return A select object with all the years starting five years from now
and five years before this year.
> */
> public Select getYearSelector(String name, Calendar now)
> {
> Select yearSelect = new Select().setName(name);
> if (onChangeSet)
> yearSelect.setOnChange(onChange);
>
> int startYear = now.get(Calendar.YEAR);
> for(int currentYear = startYear - 5; currentYear <=
startYear+5;currentYear++)
200,203c232,234
< out.append ( "<OPTION VALUE=\"" );
< out.append ( currYear );
< out.append ( "\"" );
< if ( year == currYear )
---
> Option o = new Option();
> o.addElement(Integer.toString(currentYear));
> if (startYear == currentYear)
205c236
< out.append (" SELECTED" );
---
> o.setSelected(true);
207c238,260
< out.append ( ">" + currYear + "\n" );
---
> yearSelect.addElement(o);
> }
> return(yearSelect);
> }
>
>
> /**
> Used to build the popupmenu HTML
> */
> public String output()
> {
> if ( this.useDate == null )
> {
> this.useDate.setTime ( new Date() );
> }
>
> Select monthSelect = getMonthSelector(selName, useDate);
> ConcreteElement daySelect = null;
> if (!showDays)
> {
> daySelect = new Input(Input.hidden,
> selName,
> setDay);
209,211c262,266
< out.append ("</SELECT>\n");
<
< return out.toString();
---
> else
> daySelect = getDaySelector(selName, useDate);
> Select yearSelect = getYearSelector(selName, useDate);
>
> return
(monthSelect.toString()+daySelect.toString()+yearSelect.toString());
-- CUT --
Jeffrey D. Brekke
mailto:[EMAIL PROTECTED]
http://sites.netscape.net/ekkerbj/homepage
____________________________________________________________________
Get your own FREE, personal Netscape WebMail account today at
http://webmail.netscape.com.
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]