Patches item #1439682, was opened at 2006-02-27 15:16
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=1439682&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: core
Group: 1.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Heudecker (nheudecker)
Assigned to: Nobody/Anonymous (nobody)
Summary: TimeSelector - NO VALIDATION
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.sql.Time;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
public class TimeSelector extends FormComponent
implements IChoiceRenderer {
static Log log = LogFactory.getLog(TimeSelector.class);
private static final List<String> hourList =
Arrays.asList(new String[]{"1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11", "12"});
private static final List<String> minuteList =
Arrays.asList(new String[]{"00", "05", "10",
"15", "20", "25", "30", "35", "40", "45", "50", "55"});
private static final List<String> amPmList =
Arrays.asList(new String[]{"AM", "PM"});
private DropDownChoice hours;
private DropDownChoice minutes;
private DropDownChoice amPm;
private Calendar c = Calendar.getInstance();
public TimeSelector(final String id, Time t) {
super(id);
Model hourModel = new
Model(getValueFromModel(t, Calendar.HOUR));
hours = new DropDownChoice("hour", hourModel,
hourList, this);
add(hours);
Model minuteModel = new
Model(getValueFromModel(t, Calendar.MINUTE));
minutes = new DropDownChoice("minute",
minuteModel, minuteList, this);
add(minutes);
Model amPmModel = new
Model(getValueFromModel(t, Calendar.AM_PM));
amPm = new DropDownChoice("amPm", amPmModel,
amPmList, this);
add(amPm);
}
private String getValueFromModel(Time t, int
component) {
if (t == null) {
return "";
}
c.setTime(t);
switch (component) {
case Calendar.HOUR:
return
Integer.toString(c.get(Calendar.HOUR));
case Calendar.MINUTE:
return
Integer.toString(c.get(Calendar.MINUTE));
default:
return (c.get(Calendar.AM_PM) ==
Calendar.AM) ? "AM" : "PM";
}
}
public void updateModel() {
GregorianCalendar gc = new GregorianCalendar();
String hourValue = hours.getInput();
String minuteValue = minutes.getInput();
String amPmValue = amPm.getInput();
gc.set(Calendar.HOUR, Integer.parseInt(hourValue));
gc.set(Calendar.MINUTE,
Integer.parseInt(minuteValue));
if (amPmValue.equals("AM")) {
gc.set(Calendar.AM_PM, Calendar.AM);
}
else {
gc.set(Calendar.AM_PM, Calendar.PM);
}
setModelObject(new Time(gc.getTime().getTime()));
}
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=1439682&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