You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by solomax <gi...@git.apache.org> on 2017/09/23 16:19:50 UTC

[GitHub] wicket pull request #235: Wicket 6105 java.time

GitHub user solomax opened a pull request:

    https://github.com/apache/wicket/pull/235

    Wicket 6105 java.time

    - datetime module is moved to wicketstuff
    - all references to joda-time are removed
    - The build is fixed

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/wicket WICKET-6105-java.time

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/wicket/pull/235.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #235
    
----
commit 4da2ef043aac1f681233c04d2228fca50d6e900a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Date:   2016-02-26T22:28:11Z

    WICKET-6105 Decommission wicket-datetime
    
    Move DateLabel and all Date formatters from wicket-datetime to wicket-extensions module
    WIP!

commit 1b99716338c149a6701b78cfa1acc25cfa6dd721
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Date:   2016-03-07T20:36:13Z

    WICKET-6105 Decommission Wicket-Datetime module
    
    WIP: Move some more code from -datetime to -extensions while trying to keep old APIs (j.u.Date based ones) available for easier migration

commit b82bce9cd9ee8ee203801d50c9916dd5570ac3f1
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Date:   2016-03-07T21:21:03Z

    WICKET-6105 Decommission Wicket-Datetime module
    
    WIP: Bug fixes and API improvements

commit 8019324c27739a705205e1c499f4509c0dc3c194
Author: Maxim Solodovnik <so...@gmail.com>
Date:   2017-09-13T14:38:57Z

    Merge remote-tracking branch 'origin/master' into WICKET-6105-java.time

commit a9b06ca2e23a76dd99c3e77f3fc4e9aa17a2f815
Author: Maxim Solodovnik <so...@gmail.com>
Date:   2017-09-22T14:57:06Z

    Merge branch 'master' into WICKET-6105-java.time

commit 11ef5c48962bb42e9e823d428b3fffb1d8b126b9
Author: Maxim Solodovnik <so...@gmail.com>
Date:   2017-09-22T17:20:26Z

    Wicket is compilable, tests are fails

commit 9ab8f47a980e9cd472bf731bb6496d276ee8db7a
Author: Maxim Solodovnik <so...@gmail.com>
Date:   2017-09-23T05:38:05Z

    Date-time tests are fixed

----


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    Hello All,
    
    Are we happy with these changes? Is it time to merge? :)


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    I'm just using StartExamples in wicket-examples. I've had problems with Weld before, but luckily it works for me atm.


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/wicket/pull/235


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142067840
  
    --- Diff: pom.xml ---
    @@ -89,7 +89,6 @@
     		<module>wicket</module>
     		<module>wicket-core</module>
     		<module>wicket-util</module>
    -		<module>wicket-datetime</module>
    --- End diff --
    
    So, the module will be completely removed ?!
    This is what I suggested some time ago but many devs disagreed.


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142068804
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleTimeConverter.java ---
    @@ -0,0 +1,118 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalTime;
    +import java.time.chrono.IsoChronology;
    +import java.time.format.DateTimeFormatter;
    +import java.time.format.DateTimeFormatterBuilder;
    +import java.time.format.FormatStyle;
    +import java.util.Locale;
    +
    +/**
    + * Date converter that uses javax.time and can be configured to take the time zone difference between
    + * clients and server into account, and that is configured for a certain date style. The pattern
    + * will always be locale specific.
    + * <p>
    + * This converter is especially suited on a per-component base.
    + * </p>
    + * 
    + * @see org.apache.wicket.extensions.markup.html.form.DateTextField
    + * @see java.time.LocalTime
    + * @see DateTimeFormatter
    + * 
    + * @author eelcohillenius
    --- End diff --
    
    We can remove those


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142076656
  
    --- Diff: pom.xml ---
    @@ -89,7 +89,6 @@
     		<module>wicket</module>
     		<module>wicket-core</module>
     		<module>wicket-util</module>
    -		<module>wicket-datetime</module>
    --- End diff --
    
    I see no reason to keep empty module :(
    AFAICT All valuable staff is moved to wicket-extensions


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by bitstorm <gi...@git.apache.org>.
Github user bitstorm commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    yes pleeeeease :-)


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142076722
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java ---
    @@ -0,0 +1,288 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalDate;
    +import java.time.LocalTime;
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.temporal.ChronoField;
    +import java.util.Date;
    +import java.util.Locale;
    +import java.util.TimeZone;
    +
    +import org.apache.wicket.Session;
    +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    +import org.apache.wicket.core.request.ClientInfo;
    +import org.apache.wicket.markup.html.form.FormComponentPanel;
    +import org.apache.wicket.model.IModel;
    +import org.apache.wicket.protocol.http.request.WebClientInfo;
    +
    +/**
    + * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field
    + * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field
    + * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility
    + * of the AM/PM field (see {@link DateTimeField#use12HourFormat}).
    + * <p>
    + * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an
    + * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained
    + * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling
    + * {@link #processInput()}:
    + * 
    + * <pre>{@code
    + *  DateTimeField dateTimeField = new DateTimeField(...) {
    + *    protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
    + *    {
    + *      DateTextField dateField = super.newDateTextField(id, dateFieldModel);     
    + *      dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
    + *        protected void onUpdate(AjaxRequestTarget target) {
    + *          processInput(); // let DateTimeField process input too
    + *
    + *          ...
    + *        }
    + *      });
    + *      return recorder;
    + *    }
    + *  }
    + * }</pre>
    + * 
    + * @author eelcohillenius
    + * @see DateField for a variant with just the date field and date picker
    + */
    +public class DateTimeField extends FormComponentPanel<ZonedDateTime>
    +{
    +	private static final long serialVersionUID = 1L;
    +
    +	// Component-IDs
    +	protected static final String DATE = "date";
    +	protected static final String TIME = "time";
    +
    +	// The date TextField and it's associated model object
    +	// Note that any time information in date will be ignored
    +	private DateField dateField;
    +	private TimeField timeField;
    +	private ZonedDateTime dateTime = ZonedDateTime.now();
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 */
    +	public DateTimeField(final String id)
    +	{
    +		this(id, null);
    +	}
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 * @param model
    +	 */
    +	public DateTimeField(final String id, final IModel<ZonedDateTime> model)
    +	{
    +		super(id, model);
    +
    +		// Sets the type that will be used when updating the model for this component.
    +		setType(ZonedDateTime.class);
    +
    +		// Create and add the date TextField
    +		add(dateField = newDateField(DATE, new DateModel()));
    +		add(timeField = newTimeField(TIME, new TimeModel()));
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final DateField getDateField()
    +	{
    +		return dateField;
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final TimeField getTimeField()
    +	{
    +		return timeField;
    +	}
    +
    +	@Override
    +	public String getInput()
    +	{
    +		// since we override convertInput, we can let this method return a value
    +		// that is just suitable for error reporting
    +		return String.format("%s, %s", dateField.getInput(), timeField.getInput());
    +	}
    +
    +	/**
    +	 * Gets the client's time zone.
    +	 * 
    +	 * @return The client's time zone or null
    +	 */
    +	protected ZoneId getClientTimeZone()
    +	{
    +		ClientInfo info = Session.get().getClientInfo();
    +		if (info instanceof WebClientInfo)
    +		{
    +			TimeZone timeZone = ((WebClientInfo) info).getProperties().getTimeZone();
    +			return timeZone != null ? timeZone.toZoneId() : null;
    +		}
    +		return null;
    +	}
    +
    +	/**
    +	 * Sets the converted input, which is an instance of {@link Date}, possibly null. It combines
    +	 * the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it.
    +	 * <p>
    +	 * Note that overriding this method is a better option than overriding {@link #updateModel()}
    +	 * like the first versions of this class did. The reason for that is that this method can be
    +	 * used by form validators without having to depend on the actual model being updated, and this
    +	 * method is called by the default implementation of {@link #updateModel()} anyway (so we don't
    +	 * have to override that anymore).
    +	 */
    +	@Override
    +	public void convertInput()
    +	{
    +		try
    +		{
    +			// Get the converted input values
    +			LocalDate localDate = dateField.getConvertedInput();
    +
    +			if (localDate == null)
    +			{
    +				return;
    +			}
    +
    +			// Use the input to create a date object with proper timezone
    +			LocalTime localTime = timeField.getConvertedInput();
    +			ZonedDateTime date = ZonedDateTime.of(localDate, localTime, getClientTimeZone());
    +
    +			// The date will be in the server's timezone
    +			setConvertedInput(date);
    +		}
    +		catch (RuntimeException e)
    +		{
    +			DateTimeField.this.error(e.getMessage());
    +			invalid();
    +		}
    +	}
    +
    +	/**
    +	 * create a new {@link DateField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param dateFieldModel
    +	 *            model that should be used by the {@link DateField}
    +	 * @return a new date text field instance
    +	 */
    +	protected DateField newDateField(String id, IModel<LocalDate> dateFieldModel)
    +	{
    +		return DateField.forShortStyle(id, dateFieldModel);
    +	}
    +
    +	/**
    +	 * create a new {@link TimeField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param timeFieldModel
    +	 *            model that should be used by the {@link TimeField}
    +	 * @return a new time text field instance
    +	 */
    +	protected TimeField newTimeField(String id, IModel<LocalTime> timeFieldModel)
    +	{
    +		return TimeField.forShortStyle(id, timeFieldModel);
    +	}
    +
    +	/**
    +	 * @see org.apache.wicket.Component#onBeforeRender()
    +	 */
    +	@Override
    +	protected void onBeforeRender()
    +	{
    +		dateField.setRequired(isRequired());
    +		timeField.setRequired(isRequired());
    +
    +		ZonedDateTime modelObject = getModelObject();
    +		if (modelObject == null)
    +		{
    +			dateTime = null;
    +		}
    +		else
    +		{
    +			// convert date to the client's time zone if we have that info
    +			ZoneId zone = getClientTimeZone();
    +			if (zone != null)
    +			{
    +				modelObject = modelObject.withZoneSameInstant(zone);
    +			}
    +		}
    +
    +		super.onBeforeRender();
    +	}
    +
    +	protected class DateModel implements IModel<LocalDate>
    +	{
    +		private static final long serialVersionUID = 1L;
    +
    +		@Override
    +		public LocalDate getObject()
    +		{
    +			return dateTime.toLocalDate();
    +		}
    +
    +		@Override
    +		public void setObject(LocalDate date)
    +		{
    +			dateTime = dateTime.with(ChronoField.YEAR, date.getYear());
    +			dateTime = dateTime.with(ChronoField.MONTH_OF_YEAR, date.getMonthValue());
    +			dateTime = dateTime.with(ChronoField.DAY_OF_YEAR, date.getDayOfMonth());
    +		}
    +
    +		@Override
    +		public void detach()
    +		{
    +		}
    +	}
    +
    +	protected class TimeModel implements IModel<LocalTime>
    +	{
    +		private static final long serialVersionUID = 1L;
    +
    +		@Override
    +		public LocalTime getObject()
    +		{
    +			return dateTime.toLocalTime();
    +		}
    +
    +		@Override
    +		public void setObject(LocalTime time)
    +		{
    +			dateTime = dateTime.with(ChronoField.HOUR_OF_DAY, time.getHour());
    +			dateTime = dateTime.with(ChronoField.MINUTE_OF_HOUR, time.getMinute());
    +		}
    +
    +		@Override
    +		public void detach()
    --- End diff --
    
    Addressed, thanks


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142068371
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/IDateConverter.java ---
    @@ -0,0 +1,53 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.format.DateTimeFormatter;
    +import java.util.Locale;
    +
    +import org.apache.wicket.util.convert.IConverter;
    +
    +
    +/**
    + * Base class for Joda Time based date converters. It contains the logic to parse and format,
    + * optionally taking the time zone difference between clients and the server into account.
    + * <p>
    + * Converters of this class are best suited for per-component use.
    + * </p>
    + * 
    + * @author eelcohillenius
    + */
    +public interface IDateConverter<T> extends IConverter<T>
    --- End diff --
    
    Can `T` be constraint-ed to something date related, for example java.time.temporal.Temporal ?


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142076776
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleTimeConverter.java ---
    @@ -0,0 +1,118 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalTime;
    +import java.time.chrono.IsoChronology;
    +import java.time.format.DateTimeFormatter;
    +import java.time.format.DateTimeFormatterBuilder;
    +import java.time.format.FormatStyle;
    +import java.util.Locale;
    +
    +/**
    + * Date converter that uses javax.time and can be configured to take the time zone difference between
    + * clients and server into account, and that is configured for a certain date style. The pattern
    + * will always be locale specific.
    + * <p>
    + * This converter is especially suited on a per-component base.
    + * </p>
    + * 
    + * @see org.apache.wicket.extensions.markup.html.form.DateTextField
    + * @see java.time.LocalTime
    + * @see DateTimeFormatter
    + * 
    + * @author eelcohillenius
    --- End diff --
    
    Addressed, thanks


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    This issue is too silent :(((
    Is it time to merge? Or maybe another review cycle?


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142068241
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java ---
    @@ -0,0 +1,288 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalDate;
    +import java.time.LocalTime;
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.temporal.ChronoField;
    +import java.util.Date;
    +import java.util.Locale;
    +import java.util.TimeZone;
    +
    +import org.apache.wicket.Session;
    +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    +import org.apache.wicket.core.request.ClientInfo;
    +import org.apache.wicket.markup.html.form.FormComponentPanel;
    +import org.apache.wicket.model.IModel;
    +import org.apache.wicket.protocol.http.request.WebClientInfo;
    +
    +/**
    + * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field
    + * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field
    + * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility
    + * of the AM/PM field (see {@link DateTimeField#use12HourFormat}).
    + * <p>
    + * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an
    + * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained
    + * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling
    + * {@link #processInput()}:
    + * 
    + * <pre>{@code
    + *  DateTimeField dateTimeField = new DateTimeField(...) {
    + *    protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
    + *    {
    + *      DateTextField dateField = super.newDateTextField(id, dateFieldModel);     
    + *      dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
    + *        protected void onUpdate(AjaxRequestTarget target) {
    + *          processInput(); // let DateTimeField process input too
    + *
    + *          ...
    + *        }
    + *      });
    + *      return recorder;
    + *    }
    + *  }
    + * }</pre>
    + * 
    + * @author eelcohillenius
    + * @see DateField for a variant with just the date field and date picker
    + */
    +public class DateTimeField extends FormComponentPanel<ZonedDateTime>
    +{
    +	private static final long serialVersionUID = 1L;
    +
    +	// Component-IDs
    +	protected static final String DATE = "date";
    +	protected static final String TIME = "time";
    +
    +	// The date TextField and it's associated model object
    +	// Note that any time information in date will be ignored
    +	private DateField dateField;
    +	private TimeField timeField;
    +	private ZonedDateTime dateTime = ZonedDateTime.now();
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 */
    +	public DateTimeField(final String id)
    +	{
    +		this(id, null);
    +	}
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 * @param model
    +	 */
    +	public DateTimeField(final String id, final IModel<ZonedDateTime> model)
    +	{
    +		super(id, model);
    +
    +		// Sets the type that will be used when updating the model for this component.
    +		setType(ZonedDateTime.class);
    +
    +		// Create and add the date TextField
    +		add(dateField = newDateField(DATE, new DateModel()));
    +		add(timeField = newTimeField(TIME, new TimeModel()));
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final DateField getDateField()
    +	{
    +		return dateField;
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final TimeField getTimeField()
    +	{
    +		return timeField;
    +	}
    +
    +	@Override
    +	public String getInput()
    +	{
    +		// since we override convertInput, we can let this method return a value
    +		// that is just suitable for error reporting
    +		return String.format("%s, %s", dateField.getInput(), timeField.getInput());
    +	}
    +
    +	/**
    +	 * Gets the client's time zone.
    +	 * 
    +	 * @return The client's time zone or null
    +	 */
    +	protected ZoneId getClientTimeZone()
    +	{
    +		ClientInfo info = Session.get().getClientInfo();
    +		if (info instanceof WebClientInfo)
    +		{
    +			TimeZone timeZone = ((WebClientInfo) info).getProperties().getTimeZone();
    +			return timeZone != null ? timeZone.toZoneId() : null;
    +		}
    +		return null;
    +	}
    +
    +	/**
    +	 * Sets the converted input, which is an instance of {@link Date}, possibly null. It combines
    +	 * the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it.
    +	 * <p>
    +	 * Note that overriding this method is a better option than overriding {@link #updateModel()}
    +	 * like the first versions of this class did. The reason for that is that this method can be
    +	 * used by form validators without having to depend on the actual model being updated, and this
    +	 * method is called by the default implementation of {@link #updateModel()} anyway (so we don't
    +	 * have to override that anymore).
    +	 */
    +	@Override
    +	public void convertInput()
    +	{
    +		try
    +		{
    +			// Get the converted input values
    +			LocalDate localDate = dateField.getConvertedInput();
    +
    +			if (localDate == null)
    +			{
    +				return;
    +			}
    +
    +			// Use the input to create a date object with proper timezone
    +			LocalTime localTime = timeField.getConvertedInput();
    +			ZonedDateTime date = ZonedDateTime.of(localDate, localTime, getClientTimeZone());
    +
    +			// The date will be in the server's timezone
    +			setConvertedInput(date);
    +		}
    +		catch (RuntimeException e)
    +		{
    +			DateTimeField.this.error(e.getMessage());
    +			invalid();
    +		}
    +	}
    +
    +	/**
    +	 * create a new {@link DateField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param dateFieldModel
    +	 *            model that should be used by the {@link DateField}
    +	 * @return a new date text field instance
    +	 */
    +	protected DateField newDateField(String id, IModel<LocalDate> dateFieldModel)
    +	{
    +		return DateField.forShortStyle(id, dateFieldModel);
    +	}
    +
    +	/**
    +	 * create a new {@link TimeField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param timeFieldModel
    +	 *            model that should be used by the {@link TimeField}
    +	 * @return a new time text field instance
    +	 */
    +	protected TimeField newTimeField(String id, IModel<LocalTime> timeFieldModel)
    +	{
    +		return TimeField.forShortStyle(id, timeFieldModel);
    +	}
    +
    +	/**
    +	 * @see org.apache.wicket.Component#onBeforeRender()
    +	 */
    +	@Override
    +	protected void onBeforeRender()
    +	{
    +		dateField.setRequired(isRequired());
    +		timeField.setRequired(isRequired());
    +
    +		ZonedDateTime modelObject = getModelObject();
    +		if (modelObject == null)
    +		{
    +			dateTime = null;
    +		}
    +		else
    +		{
    +			// convert date to the client's time zone if we have that info
    +			ZoneId zone = getClientTimeZone();
    +			if (zone != null)
    +			{
    +				modelObject = modelObject.withZoneSameInstant(zone);
    +			}
    +		}
    +
    +		super.onBeforeRender();
    +	}
    +
    +	protected class DateModel implements IModel<LocalDate>
    +	{
    +		private static final long serialVersionUID = 1L;
    +
    +		@Override
    +		public LocalDate getObject()
    +		{
    +			return dateTime.toLocalDate();
    +		}
    +
    +		@Override
    +		public void setObject(LocalDate date)
    +		{
    +			dateTime = dateTime.with(ChronoField.YEAR, date.getYear());
    +			dateTime = dateTime.with(ChronoField.MONTH_OF_YEAR, date.getMonthValue());
    +			dateTime = dateTime.with(ChronoField.DAY_OF_YEAR, date.getDayOfMonth());
    +		}
    +
    +		@Override
    +		public void detach()
    --- End diff --
    
    This is not needed. The default impl in IModel does the same.


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    I've pushed my changes with many changes:
    - datetime is now partially reusing the new java.time converters in core
    - unnecessary converter in TimeField removed
    - core's ZonedDateTImeConverter includes the timezone for formatting too
    - renamed fields with text input to LocalDateTextField and new LocalTimeTextFIeld
    - LocalTimeField, LocalDateTimeField and ZonedDateTimeFIeld are better FormComponents now
    - ZonedToLocalDateTimeModel allows converting ZonedDateTime to LocalDateTime in the client's timezone
    - the example shows more features now
    
    Sorry, I've referenced the wrong issue in the commit, I'll clean this up once we merge this branch into master.


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    old date examples are still available at wicketstuff, what is "example's compref"?


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142083823
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java ---
    @@ -227,14 +216,10 @@ public DateLabel(String id, DateConverter converter)
     	 * @param converter
     	 *            The converter to use
     	 */
    -	public DateLabel(String id, IModel<Date> model, DateConverter converter)
    +	public DateLabel(String id, IModel<LocalDate> model, ZonedDateTimeConverter converter)
    --- End diff --
    
    This looks wrong: DateLabel works on a LocalDate now, but uses a ZonedDateTimeConverter which converts to/from ZonedDateTime. IMHO we should change this to LocalDate, or we could just delete this class, since it is just a collection of factory methods plus this weird "before" and "after" rendering.


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142088563
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java ---
    @@ -0,0 +1,278 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalDate;
    +import java.time.LocalTime;
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.temporal.ChronoField;
    +import java.util.Date;
    +import java.util.Locale;
    +import java.util.TimeZone;
    +
    +import org.apache.wicket.Session;
    +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    +import org.apache.wicket.core.request.ClientInfo;
    +import org.apache.wicket.markup.html.form.FormComponentPanel;
    +import org.apache.wicket.model.IModel;
    +import org.apache.wicket.protocol.http.request.WebClientInfo;
    +
    +/**
    + * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field
    + * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field
    + * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility
    + * of the AM/PM field (see {@link DateTimeField#use12HourFormat}).
    + * <p>
    + * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an
    + * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained
    + * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling
    + * {@link #processInput()}:
    + * 
    + * <pre>{@code
    + *  DateTimeField dateTimeField = new DateTimeField(...) {
    + *    protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
    + *    {
    + *      DateTextField dateField = super.newDateTextField(id, dateFieldModel);     
    + *      dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
    + *        protected void onUpdate(AjaxRequestTarget target) {
    + *          processInput(); // let DateTimeField process input too
    + *
    + *          ...
    + *        }
    + *      });
    + *      return recorder;
    + *    }
    + *  }
    + * }</pre>
    + * 
    + * @author eelcohillenius
    + * @see DateField for a variant with just the date field and date picker
    + */
    +public class DateTimeField extends FormComponentPanel<ZonedDateTime>
    --- End diff --
    
    Will add additional component


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    Is it time to merge this PR and pack M8? ;)


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142068252
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java ---
    @@ -0,0 +1,288 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalDate;
    +import java.time.LocalTime;
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.temporal.ChronoField;
    +import java.util.Date;
    +import java.util.Locale;
    +import java.util.TimeZone;
    +
    +import org.apache.wicket.Session;
    +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    +import org.apache.wicket.core.request.ClientInfo;
    +import org.apache.wicket.markup.html.form.FormComponentPanel;
    +import org.apache.wicket.model.IModel;
    +import org.apache.wicket.protocol.http.request.WebClientInfo;
    +
    +/**
    + * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field
    + * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field
    + * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility
    + * of the AM/PM field (see {@link DateTimeField#use12HourFormat}).
    + * <p>
    + * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an
    + * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained
    + * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling
    + * {@link #processInput()}:
    + * 
    + * <pre>{@code
    + *  DateTimeField dateTimeField = new DateTimeField(...) {
    + *    protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
    + *    {
    + *      DateTextField dateField = super.newDateTextField(id, dateFieldModel);     
    + *      dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
    + *        protected void onUpdate(AjaxRequestTarget target) {
    + *          processInput(); // let DateTimeField process input too
    + *
    + *          ...
    + *        }
    + *      });
    + *      return recorder;
    + *    }
    + *  }
    + * }</pre>
    + * 
    + * @author eelcohillenius
    + * @see DateField for a variant with just the date field and date picker
    + */
    +public class DateTimeField extends FormComponentPanel<ZonedDateTime>
    +{
    +	private static final long serialVersionUID = 1L;
    +
    +	// Component-IDs
    +	protected static final String DATE = "date";
    +	protected static final String TIME = "time";
    +
    +	// The date TextField and it's associated model object
    +	// Note that any time information in date will be ignored
    +	private DateField dateField;
    +	private TimeField timeField;
    +	private ZonedDateTime dateTime = ZonedDateTime.now();
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 */
    +	public DateTimeField(final String id)
    +	{
    +		this(id, null);
    +	}
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 * @param model
    +	 */
    +	public DateTimeField(final String id, final IModel<ZonedDateTime> model)
    +	{
    +		super(id, model);
    +
    +		// Sets the type that will be used when updating the model for this component.
    +		setType(ZonedDateTime.class);
    +
    +		// Create and add the date TextField
    +		add(dateField = newDateField(DATE, new DateModel()));
    +		add(timeField = newTimeField(TIME, new TimeModel()));
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final DateField getDateField()
    +	{
    +		return dateField;
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final TimeField getTimeField()
    +	{
    +		return timeField;
    +	}
    +
    +	@Override
    +	public String getInput()
    +	{
    +		// since we override convertInput, we can let this method return a value
    +		// that is just suitable for error reporting
    +		return String.format("%s, %s", dateField.getInput(), timeField.getInput());
    +	}
    +
    +	/**
    +	 * Gets the client's time zone.
    +	 * 
    +	 * @return The client's time zone or null
    +	 */
    +	protected ZoneId getClientTimeZone()
    +	{
    +		ClientInfo info = Session.get().getClientInfo();
    +		if (info instanceof WebClientInfo)
    +		{
    +			TimeZone timeZone = ((WebClientInfo) info).getProperties().getTimeZone();
    +			return timeZone != null ? timeZone.toZoneId() : null;
    +		}
    +		return null;
    +	}
    +
    +	/**
    +	 * Sets the converted input, which is an instance of {@link Date}, possibly null. It combines
    +	 * the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it.
    +	 * <p>
    +	 * Note that overriding this method is a better option than overriding {@link #updateModel()}
    +	 * like the first versions of this class did. The reason for that is that this method can be
    +	 * used by form validators without having to depend on the actual model being updated, and this
    +	 * method is called by the default implementation of {@link #updateModel()} anyway (so we don't
    +	 * have to override that anymore).
    +	 */
    +	@Override
    +	public void convertInput()
    +	{
    +		try
    +		{
    +			// Get the converted input values
    +			LocalDate localDate = dateField.getConvertedInput();
    +
    +			if (localDate == null)
    +			{
    +				return;
    +			}
    +
    +			// Use the input to create a date object with proper timezone
    +			LocalTime localTime = timeField.getConvertedInput();
    +			ZonedDateTime date = ZonedDateTime.of(localDate, localTime, getClientTimeZone());
    +
    +			// The date will be in the server's timezone
    +			setConvertedInput(date);
    +		}
    +		catch (RuntimeException e)
    +		{
    +			DateTimeField.this.error(e.getMessage());
    +			invalid();
    +		}
    +	}
    +
    +	/**
    +	 * create a new {@link DateField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param dateFieldModel
    +	 *            model that should be used by the {@link DateField}
    +	 * @return a new date text field instance
    +	 */
    +	protected DateField newDateField(String id, IModel<LocalDate> dateFieldModel)
    +	{
    +		return DateField.forShortStyle(id, dateFieldModel);
    +	}
    +
    +	/**
    +	 * create a new {@link TimeField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param timeFieldModel
    +	 *            model that should be used by the {@link TimeField}
    +	 * @return a new time text field instance
    +	 */
    +	protected TimeField newTimeField(String id, IModel<LocalTime> timeFieldModel)
    +	{
    +		return TimeField.forShortStyle(id, timeFieldModel);
    +	}
    +
    +	/**
    +	 * @see org.apache.wicket.Component#onBeforeRender()
    +	 */
    +	@Override
    +	protected void onBeforeRender()
    +	{
    +		dateField.setRequired(isRequired());
    +		timeField.setRequired(isRequired());
    +
    +		ZonedDateTime modelObject = getModelObject();
    +		if (modelObject == null)
    +		{
    +			dateTime = null;
    +		}
    +		else
    +		{
    +			// convert date to the client's time zone if we have that info
    +			ZoneId zone = getClientTimeZone();
    +			if (zone != null)
    +			{
    +				modelObject = modelObject.withZoneSameInstant(zone);
    +			}
    +		}
    +
    +		super.onBeforeRender();
    +	}
    +
    +	protected class DateModel implements IModel<LocalDate>
    +	{
    +		private static final long serialVersionUID = 1L;
    +
    +		@Override
    +		public LocalDate getObject()
    +		{
    +			return dateTime.toLocalDate();
    +		}
    +
    +		@Override
    +		public void setObject(LocalDate date)
    +		{
    +			dateTime = dateTime.with(ChronoField.YEAR, date.getYear());
    +			dateTime = dateTime.with(ChronoField.MONTH_OF_YEAR, date.getMonthValue());
    +			dateTime = dateTime.with(ChronoField.DAY_OF_YEAR, date.getDayOfMonth());
    +		}
    +
    +		@Override
    +		public void detach()
    +		{
    +		}
    +	}
    +
    +	protected class TimeModel implements IModel<LocalTime>
    +	{
    +		private static final long serialVersionUID = 1L;
    +
    +		@Override
    +		public LocalTime getObject()
    +		{
    +			return dateTime.toLocalTime();
    +		}
    +
    +		@Override
    +		public void setObject(LocalTime time)
    +		{
    +			dateTime = dateTime.with(ChronoField.HOUR_OF_DAY, time.getHour());
    +			dateTime = dateTime.with(ChronoField.MINUTE_OF_HOUR, time.getMinute());
    +		}
    +
    +		@Override
    +		public void detach()
    --- End diff --
    
    Not needed


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142088478
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java ---
    @@ -227,14 +216,10 @@ public DateLabel(String id, DateConverter converter)
     	 * @param converter
     	 *            The converter to use
     	 */
    -	public DateLabel(String id, IModel<Date> model, DateConverter converter)
    +	public DateLabel(String id, IModel<LocalDate> model, ZonedDateTimeConverter converter)
    --- End diff --
    
    +1 for delete


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    I did homework (partially) and added some tests :)
    Could you please check them and maybe add some more? :))


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142076708
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java ---
    @@ -0,0 +1,288 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalDate;
    +import java.time.LocalTime;
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.temporal.ChronoField;
    +import java.util.Date;
    +import java.util.Locale;
    +import java.util.TimeZone;
    +
    +import org.apache.wicket.Session;
    +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    +import org.apache.wicket.core.request.ClientInfo;
    +import org.apache.wicket.markup.html.form.FormComponentPanel;
    +import org.apache.wicket.model.IModel;
    +import org.apache.wicket.protocol.http.request.WebClientInfo;
    +
    +/**
    + * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field
    + * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field
    + * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility
    + * of the AM/PM field (see {@link DateTimeField#use12HourFormat}).
    + * <p>
    + * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an
    + * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained
    + * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling
    + * {@link #processInput()}:
    + * 
    + * <pre>{@code
    + *  DateTimeField dateTimeField = new DateTimeField(...) {
    + *    protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
    + *    {
    + *      DateTextField dateField = super.newDateTextField(id, dateFieldModel);     
    + *      dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
    + *        protected void onUpdate(AjaxRequestTarget target) {
    + *          processInput(); // let DateTimeField process input too
    + *
    + *          ...
    + *        }
    + *      });
    + *      return recorder;
    + *    }
    + *  }
    + * }</pre>
    + * 
    + * @author eelcohillenius
    + * @see DateField for a variant with just the date field and date picker
    + */
    +public class DateTimeField extends FormComponentPanel<ZonedDateTime>
    +{
    +	private static final long serialVersionUID = 1L;
    +
    +	// Component-IDs
    +	protected static final String DATE = "date";
    +	protected static final String TIME = "time";
    +
    +	// The date TextField and it's associated model object
    +	// Note that any time information in date will be ignored
    +	private DateField dateField;
    +	private TimeField timeField;
    +	private ZonedDateTime dateTime = ZonedDateTime.now();
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 */
    +	public DateTimeField(final String id)
    +	{
    +		this(id, null);
    +	}
    +
    +	/**
    +	 * Construct.
    +	 * 
    +	 * @param id
    +	 * @param model
    +	 */
    +	public DateTimeField(final String id, final IModel<ZonedDateTime> model)
    +	{
    +		super(id, model);
    +
    +		// Sets the type that will be used when updating the model for this component.
    +		setType(ZonedDateTime.class);
    +
    +		// Create and add the date TextField
    +		add(dateField = newDateField(DATE, new DateModel()));
    +		add(timeField = newTimeField(TIME, new TimeModel()));
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final DateField getDateField()
    +	{
    +		return dateField;
    +	}
    +
    +	/**
    +	 * 
    +	 * @return The date TextField
    +	 */
    +	protected final TimeField getTimeField()
    +	{
    +		return timeField;
    +	}
    +
    +	@Override
    +	public String getInput()
    +	{
    +		// since we override convertInput, we can let this method return a value
    +		// that is just suitable for error reporting
    +		return String.format("%s, %s", dateField.getInput(), timeField.getInput());
    +	}
    +
    +	/**
    +	 * Gets the client's time zone.
    +	 * 
    +	 * @return The client's time zone or null
    +	 */
    +	protected ZoneId getClientTimeZone()
    +	{
    +		ClientInfo info = Session.get().getClientInfo();
    +		if (info instanceof WebClientInfo)
    +		{
    +			TimeZone timeZone = ((WebClientInfo) info).getProperties().getTimeZone();
    +			return timeZone != null ? timeZone.toZoneId() : null;
    +		}
    +		return null;
    +	}
    +
    +	/**
    +	 * Sets the converted input, which is an instance of {@link Date}, possibly null. It combines
    +	 * the inputs of the nested date, hours, minutes and am/pm fields and constructs a date from it.
    +	 * <p>
    +	 * Note that overriding this method is a better option than overriding {@link #updateModel()}
    +	 * like the first versions of this class did. The reason for that is that this method can be
    +	 * used by form validators without having to depend on the actual model being updated, and this
    +	 * method is called by the default implementation of {@link #updateModel()} anyway (so we don't
    +	 * have to override that anymore).
    +	 */
    +	@Override
    +	public void convertInput()
    +	{
    +		try
    +		{
    +			// Get the converted input values
    +			LocalDate localDate = dateField.getConvertedInput();
    +
    +			if (localDate == null)
    +			{
    +				return;
    +			}
    +
    +			// Use the input to create a date object with proper timezone
    +			LocalTime localTime = timeField.getConvertedInput();
    +			ZonedDateTime date = ZonedDateTime.of(localDate, localTime, getClientTimeZone());
    +
    +			// The date will be in the server's timezone
    +			setConvertedInput(date);
    +		}
    +		catch (RuntimeException e)
    +		{
    +			DateTimeField.this.error(e.getMessage());
    +			invalid();
    +		}
    +	}
    +
    +	/**
    +	 * create a new {@link DateField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param dateFieldModel
    +	 *            model that should be used by the {@link DateField}
    +	 * @return a new date text field instance
    +	 */
    +	protected DateField newDateField(String id, IModel<LocalDate> dateFieldModel)
    +	{
    +		return DateField.forShortStyle(id, dateFieldModel);
    +	}
    +
    +	/**
    +	 * create a new {@link TimeField} instance to be added to this panel.
    +	 * 
    +	 * @param id
    +	 *            the component id
    +	 * @param timeFieldModel
    +	 *            model that should be used by the {@link TimeField}
    +	 * @return a new time text field instance
    +	 */
    +	protected TimeField newTimeField(String id, IModel<LocalTime> timeFieldModel)
    +	{
    +		return TimeField.forShortStyle(id, timeFieldModel);
    +	}
    +
    +	/**
    +	 * @see org.apache.wicket.Component#onBeforeRender()
    +	 */
    +	@Override
    +	protected void onBeforeRender()
    +	{
    +		dateField.setRequired(isRequired());
    +		timeField.setRequired(isRequired());
    +
    +		ZonedDateTime modelObject = getModelObject();
    +		if (modelObject == null)
    +		{
    +			dateTime = null;
    +		}
    +		else
    +		{
    +			// convert date to the client's time zone if we have that info
    +			ZoneId zone = getClientTimeZone();
    +			if (zone != null)
    +			{
    +				modelObject = modelObject.withZoneSameInstant(zone);
    +			}
    +		}
    +
    +		super.onBeforeRender();
    +	}
    +
    +	protected class DateModel implements IModel<LocalDate>
    +	{
    +		private static final long serialVersionUID = 1L;
    +
    +		@Override
    +		public LocalDate getObject()
    +		{
    +			return dateTime.toLocalDate();
    +		}
    +
    +		@Override
    +		public void setObject(LocalDate date)
    +		{
    +			dateTime = dateTime.with(ChronoField.YEAR, date.getYear());
    +			dateTime = dateTime.with(ChronoField.MONTH_OF_YEAR, date.getMonthValue());
    +			dateTime = dateTime.with(ChronoField.DAY_OF_YEAR, date.getDayOfMonth());
    +		}
    +
    +		@Override
    +		public void detach()
    --- End diff --
    
    Addressed, thanks


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142076762
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/IDateConverter.java ---
    @@ -0,0 +1,53 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.format.DateTimeFormatter;
    +import java.util.Locale;
    +
    +import org.apache.wicket.util.convert.IConverter;
    +
    +
    +/**
    + * Base class for Joda Time based date converters. It contains the logic to parse and format,
    + * optionally taking the time zone difference between clients and the server into account.
    + * <p>
    + * Converters of this class are best suited for per-component use.
    + * </p>
    + * 
    + * @author eelcohillenius
    + */
    +public interface IDateConverter<T> extends IConverter<T>
    --- End diff --
    
    Addressed, thanks


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    Everything seems to work :)
    Time for another (final?) review? :))


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142068292
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/IDateConverter.java ---
    @@ -0,0 +1,53 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.format.DateTimeFormatter;
    +import java.util.Locale;
    +
    +import org.apache.wicket.util.convert.IConverter;
    +
    +
    +/**
    + * Base class for Joda Time based date converters. It contains the logic to parse and format,
    --- End diff --
    
    Joda ?!


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142076750
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/IDateConverter.java ---
    @@ -0,0 +1,53 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.format.DateTimeFormatter;
    +import java.util.Locale;
    +
    +import org.apache.wicket.util.convert.IConverter;
    +
    +
    +/**
    + * Base class for Joda Time based date converters. It contains the logic to parse and format,
    --- End diff --
    
    Addressed, thanks


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    Sorry, I'm busy currently.
    
    But I identified major flaws in the current implementation, just as an example: TimeField holds a converter now, but never uses it :(.
    Usages of FormComponentPanel haven't been ideal in wicket-datetime either, so we should improve that.
    There are many more things I've been working on, so expect a huge change (hopefully soon).


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    We should show the usage of these 'new' components in wicket-examples, under "component reference".


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    Hello @svenmeier maybe I can help with the changes need to be done?
    I really need M8 to be released :))


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142085534
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java ---
    @@ -0,0 +1,278 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.LocalDate;
    +import java.time.LocalTime;
    +import java.time.ZoneId;
    +import java.time.ZonedDateTime;
    +import java.time.temporal.ChronoField;
    +import java.util.Date;
    +import java.util.Locale;
    +import java.util.TimeZone;
    +
    +import org.apache.wicket.Session;
    +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
    +import org.apache.wicket.core.request.ClientInfo;
    +import org.apache.wicket.markup.html.form.FormComponentPanel;
    +import org.apache.wicket.model.IModel;
    +import org.apache.wicket.protocol.http.request.WebClientInfo;
    +
    +/**
    + * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field
    + * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field
    + * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility
    + * of the AM/PM field (see {@link DateTimeField#use12HourFormat}).
    + * <p>
    + * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an
    + * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained
    + * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling
    + * {@link #processInput()}:
    + * 
    + * <pre>{@code
    + *  DateTimeField dateTimeField = new DateTimeField(...) {
    + *    protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
    + *    {
    + *      DateTextField dateField = super.newDateTextField(id, dateFieldModel);     
    + *      dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
    + *        protected void onUpdate(AjaxRequestTarget target) {
    + *          processInput(); // let DateTimeField process input too
    + *
    + *          ...
    + *        }
    + *      });
    + *      return recorder;
    + *    }
    + *  }
    + * }</pre>
    + * 
    + * @author eelcohillenius
    + * @see DateField for a variant with just the date field and date picker
    + */
    +public class DateTimeField extends FormComponentPanel<ZonedDateTime>
    --- End diff --
    
    For consistency I'd prefer DateTimeField working on a LocalDateTime - for me this is the default pick instead of ZonedDateTime.
    
    Maybe we need two components, one for each type?


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    IDateConverter is removed, Will try to add additional tests as soon as I get more free time
    
    BTW how are you running wicket-examples? it fail to start for me :(
    `mvn jetty:run`
    
    ```
    [WARNING] 
    java.lang.IllegalStateException: WELD-ENV-000033: Invalid bean archive scanning result - found multiple results with the same reference: /home/solomax/work/wicket/wicket-examples/target/classes
    	at org.jboss.weld.environment.deployment.discovery.AbstractDiscoveryStrategy.performDiscovery(AbstractDiscoveryStrategy.java:96)
    	at org.jboss.weld.environment.servlet.WeldServletLifecycle.createDeployment(WeldServletLifecycle.java:311)
    	at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:163)
    	at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:61)
    	at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:140)
    
    ```
    



---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by solomax <gi...@git.apache.org>.
Github user solomax commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    I'll create `org.apache.wicket.examples.datetime` later tonight taking `org.apache.wicket.examples.captcha` as reference :)


---

[GitHub] wicket pull request #235: Wicket 6105 java.time

Posted by martin-g <gi...@git.apache.org>.
Github user martin-g commented on a diff in the pull request:

    https://github.com/apache/wicket/pull/235#discussion_r142068495
  
    --- Diff: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/IDateConverter.java ---
    @@ -0,0 +1,53 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.wicket.extensions.markup.html.form.datetime;
    +
    +import java.time.format.DateTimeFormatter;
    +import java.util.Locale;
    +
    +import org.apache.wicket.util.convert.IConverter;
    +
    +
    +/**
    + * Base class for Joda Time based date converters. It contains the logic to parse and format,
    + * optionally taking the time zone difference between clients and the server into account.
    + * <p>
    + * Converters of this class are best suited for per-component use.
    + * </p>
    + * 
    + * @author eelcohillenius
    + */
    +public interface IDateConverter<T> extends IConverter<T>
    --- End diff --
    
    If NOT, then maybe make this interface package-private ?!


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    IMHO we should drop IDateConverter:
    This interface is just used inside the package and the relevant places could just use LocalDateConverter/LocalTimeConverter instead.


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by bitstorm <gi...@git.apache.org>.
Github user bitstorm commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    I would also glad to help solving the remaining tasks/issuse for this branch :) 


---

[GitHub] wicket issue #235: Wicket 6105 java.time

Posted by svenmeier <gi...@git.apache.org>.
Github user svenmeier commented on the issue:

    https://github.com/apache/wicket/pull/235
  
    Still some things to improve on ... I'll work on it tomorrow.


---