Hmm... If I were designing a component like this (and for some reason didn't
like the ones out there like datepicker that already do this)  I'd make a
new component that extends panel with 2 separate child controls, each with
their own date models.  Then use a top level model  getter / setter that
just pushes/pulls the 2 child dates independently using the
java.util.Calendar's fields independently.

Hope that helps,
-- Jim.

On Thu, Mar 17, 2011 at 2:53 PM, nino martinez wael <
nino.martinez.w...@gmail.com> wrote:

> Hi
>
> Essentially I've made my own datepicker and timepicker using some jquery
> components. I am having my two components editing the same model (one edits
> time and the other date). Both components extending datetextfield
>
> Problem are if I change time then month/day are reset. Im thinking that it
> has something todo with hourdatetextfield are the last component added.
> I've
> tried various things also editing the raw model object. Nothing works..
>
>
>
> public class HourDateTextField extends DateTextField {
>
> public HourDateTextField(String id, IModel<Date> model,
> DateConverter converter) {
> super(id, model, converter);
>
> add(new TimePickerBehavior());
> }
>
> @Override
> protected void convertInput() {
> MutableDateTime dateOld = new MutableDateTime(getModelObject());
> super.convertInput();
> Date dateNew = this.getConvertedInput();
> dateOld.setHourOfDay(dateNew.getHours());
> dateOld.setMinuteOfHour(dateNew.getMinutes());
> setModelObject(dateOld.toDate());
>
> }
>
> }
>
> public class MonthDayDateTextField extends DateTextField {
>
> public MonthDayDateTextField(String id, IModel<Date> model,
> DateConverter converter) {
> super(id, model, converter);
>
> add(new DatePickerBehavior());
> }
>
> @Override
> protected void convertInput() {
>
> MutableDateTime dateOld = new MutableDateTime(getModelObject());
> super.convertInput();
> Date dateNew = this.getConvertedInput();
> dateOld.setDayOfMonth(dateNew.getDay());
> dateOld.setMonthOfYear(dateNew.getMonth());
> setModelObject(dateOld.toDate());
>
> }
>
> }
>

Reply via email to