filter your models to preserve their respective parts, for example
below is a model you would assign to the textfield that edits the date
part. you would need to build the opposite for your textfield that
edits the time part.
-igor
/**
* Only modifies the date portion of the adapted {@link Date} model
*
* @author igor
*
*/
public class DateFilterModel extends AdapterModel<Date, Date>
{
public DateFilterModel(IModel<Date> delegate)
{
super(delegate);
}
@Override
protected Date getObject(IModel<Date> delegate)
{
Date source = delegate.getObject();
return (source != null) ? new Date(source.getTime()) : null;
}
@Override
protected void setObject(Date object, IModel<Date> delegate)
{
if (object == null)
{
delegate.setObject(null);
}
else if (delegate.getObject() == null)
{
delegate.setObject(new Date(object.getTime()));
}
else
{
LocalDate src = new LocalDate(object.getTime());
LocalDateTime dest = new
LocalDateTime(delegate.getObject().getTime()).withYear(src.getYear())
.withMonthOfYear(src.getMonthOfYear())
.withDayOfMonth(src.getDayOfMonth());
delegate.setObject(dest.toDateTime().toDate());
}
}
}
On Thu, Mar 17, 2011 at 11:53 AM, nino martinez wael
<[email protected]> 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());
>
> }
>
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]