Patches item #1439755, was opened at 2006-02-27 16:54
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=684977&aid=1439755&group_id=119783
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Heudecker (nheudecker)
Assigned to: Nobody/Anonymous (nobody)
Summary: DateSelector - CORRECTED
Initial Comment:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wicket.markup.html.form.DropDownChoice;
import wicket.markup.html.form.FormComponent;
import wicket.markup.html.form.IChoiceRenderer;
import wicket.model.Model;
import java.util.*;
public class DateSelector extends FormComponent
implements IChoiceRenderer {
static Log log = LogFactory.getLog(DateSelector.class);
private static final List<String> monthsList =
Arrays.asList(new String[] {"Jan", "Feb",
"Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"});
private static final List<String> daysList =
Arrays.asList(new String[]
{"1","2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16","17","18","19","20","21","22","23",
"24","25","26","27","28","29","30","31"});
private DropDownChoice months;
private DropDownChoice days;
private DropDownChoice years;
private Calendar c = Calendar.getInstance();
public DateSelector(final String id, Date date) {
super(id);
init(date);
}
private void init(Date d) {
Model monthModel = new
Model(getValueFromModel(d, Calendar.MONTH));
months = new DropDownChoice("months",
monthModel, monthsList, this);
add(months);
Model dayModel = new Model(getValueFromModel(d,
Calendar.DAY_OF_MONTH));
days = new DropDownChoice("days", dayModel,
daysList, this);
add(days);
Model yearModel = new
Model(getValueFromModel(d, Calendar.YEAR));
years = new DropDownChoice("years", yearModel,
getYearsList(), this);
add(years);
}
public void updateModel() {
GregorianCalendar gc = new GregorianCalendar();
String monthSelected = months.getInput();
String daySelected = days.getInput();
String yearSelected = years.getInput();
gc.set(Calendar.MONTH,
getMonthIndex(monthSelected));
gc.set(Calendar.DAY_OF_MONTH,
Integer.parseInt(daySelected));
gc.set(Calendar.YEAR,
Integer.parseInt(yearSelected));
setModelObject(gc.getTime());
}
private String getValueFromModel(Date d, int
component) {
if (d == null) {
return "";
}
c.setTime(d);
switch (component) {
case Calendar.MONTH:
return getMonthName(c.get(Calendar.MONTH));
case Calendar.DAY_OF_MONTH:
return
Integer.toString(c.get(Calendar.DAY_OF_MONTH));
default:
return
Integer.toString(c.get(Calendar.YEAR));
}
}
private List<String> getYearsList() {
String[] years = new String[10];
int n = 0;
for (int i = new
GregorianCalendar().get(Calendar.YEAR); n < 10; i++) {
years[n] = Integer.toString(i);
n++;
}
return Arrays.asList(years);
}
private String getMonthName(int month) {
switch (month) {
case Calendar.JANUARY: return "Jan";
case Calendar.FEBRUARY: return "Feb";
case Calendar.MARCH: return "Mar";
case Calendar.APRIL: return "Apr";
case Calendar.MAY: return "May";
case Calendar.JUNE: return "Jun";
case Calendar.JULY: return "Jul";
case Calendar.AUGUST: return "Aug";
case Calendar.SEPTEMBER: return "Sep";
case Calendar.OCTOBER: return "Oct";
case Calendar.NOVEMBER: return "Nov";
default: return "Dec";
}
}
private int getMonthIndex(String value) {
for (int i = 0; i < monthsList.size(); i++) {
String m = monthsList.get(i);
if (value.equals(m)) {
return i;
}
}
return 0;
}
public String getDisplayValue(Object object) {
return object.toString();
}
public String getIdValue(Object object, int i) {
return object.toString();
}
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=684977&aid=1439755&group_id=119783
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop