You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2016/03/08 09:33:36 UTC

[2/2] wicket git commit: WICKET-6105 Decommission Wicket-Datetime module

WICKET-6105 Decommission Wicket-Datetime module

WIP: Bug fixes and API improvements


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b82bce9c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b82bce9c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b82bce9c

Branch: refs/heads/WICKET-6105-java.time
Commit: b82bce9cd9ee8ee203801d50c9916dd5570ac3f1
Parents: 1b99716
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Mar 7 22:21:03 2016 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Mar 7 22:21:03 2016 +0100

----------------------------------------------------------------------
 .../html/form/datetime/DateTimeField.java       | 36 ++++++++++++++++----
 .../html/form/datetime/StyleDateConverter.java  | 16 ++++-----
 2 files changed, 37 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/b82bce9c/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java
index 82142f0..18c8d31 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java
@@ -55,7 +55,7 @@ import org.apache.wicket.validation.validator.RangeValidator;
  * <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 DateTextField} by overriding {@link #newDateTextField(String, PropertyModel)} and calling
+ * {@link DateTextField} by overriding {@link #newDateTextField(String, IModel)} and calling
  * {@link #processInput()}:
  * 
  * <pre>
@@ -104,7 +104,7 @@ public class DateTimeField extends FormComponentPanel<ZonedDateTime>
 	private static final long serialVersionUID = 1L;
 
 	// Component-IDs
-	protected static final String DATE = "hours";
+	protected static final String DATE = "date";
 	protected static final String HOURS = "hours";
 	protected static final String MINUTES = "minutes";
 	protected static final String AM_OR_PM_CHOICE = "amOrPmChoice";
@@ -125,7 +125,7 @@ public class DateTimeField extends FormComponentPanel<ZonedDateTime>
 	// The date TextField and it's associated model object
 	// Note that any time information in date will be ignored
 	private DateTextField dateField;
-	private ZonedDateTime dateTime;
+	private ZonedDateTime dateTime = ZonedDateTime.now();
 
 	// The TextField for "hours" and it's associated model object
 	private TextField<Integer> hoursField;
@@ -157,8 +157,7 @@ public class DateTimeField extends FormComponentPanel<ZonedDateTime>
 		setType(Date.class);
 
 		// Create and add the date TextField
-		PropertyModel<LocalDate> dateFieldModel = new PropertyModel<>(this, DATE);
-		add(dateField = newDateTextField(DATE, dateFieldModel));
+		add(dateField = newDateTextField(DATE, new DateModel()));
 
 		// Add a date picker to the date TextField
 //		dateField.add(newDatePicker());
@@ -306,7 +305,7 @@ public class DateTimeField extends FormComponentPanel<ZonedDateTime>
 		if (info instanceof WebClientInfo)
 		{
 			TimeZone timeZone = ((WebClientInfo) info).getProperties().getTimeZone();
-			return timeZone.toZoneId();
+			return timeZone != null ? timeZone.toZoneId() : null;
 		}
 		return null;
 	}
@@ -390,7 +389,7 @@ public class DateTimeField extends FormComponentPanel<ZonedDateTime>
 	 *            model that should be used by the {@link DateTextField}
 	 * @return a new date text field instance
 	 */
-	protected DateTextField newDateTextField(String id, PropertyModel<LocalDate> dateFieldModel)
+	protected DateTextField newDateTextField(String id, IModel<LocalDate> dateFieldModel)
 	{
 		return DateTextField.forShortStyle(id, dateFieldModel, false);
 	}
@@ -512,6 +511,29 @@ public class DateTimeField extends FormComponentPanel<ZonedDateTime>
 //		};
 //	}
 
+
+	protected class DateModel implements IModel<LocalDate>
+	{
+		@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 HoursModel implements IModel<Integer>
 	{
 		@Override

http://git-wip-us.apache.org/repos/asf/wicket/blob/b82bce9c/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleDateConverter.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleDateConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleDateConverter.java
index 9eef6c5..8815ce5 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleDateConverter.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/StyleDateConverter.java
@@ -16,12 +16,13 @@
  */
 package org.apache.wicket.extensions.markup.html.form.datetime;
 
+import java.time.chrono.Chronology;
+import java.time.chrono.IsoChronology;
 import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.FormatStyle;
 import java.util.Locale;
 
-import org.apache.wicket.util.lang.Args;
-
 /**
  * Date converter that uses Joda 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
@@ -63,7 +64,7 @@ public class StyleDateConverter extends DateConverter
 	 */
 	public StyleDateConverter(boolean applyTimeZoneDifference)
 	{
-		this(FormatStyle.SHORT, FormatStyle.SHORT, applyTimeZoneDifference);
+		this(FormatStyle.SHORT, null, applyTimeZoneDifference);
 	}
 
 	/**
@@ -88,8 +89,8 @@ public class StyleDateConverter extends DateConverter
 	public StyleDateConverter(FormatStyle dateStyle, FormatStyle timeStyle, boolean applyTimeZoneDifference)
 	{
 		super(applyTimeZoneDifference);
-		this.dateStyle = Args.notNull(dateStyle, "dateStyle");
-		this.timeStyle = Args.notNull(timeStyle, "timeStyle");
+		this.dateStyle = dateStyle;
+		this.timeStyle = timeStyle;
 	}
 
 	public StyleDateConverter(String dateTimeStyle, boolean applyTimeZoneDifference)
@@ -102,12 +103,11 @@ public class StyleDateConverter extends DateConverter
 	 * 
 	 * @return datePattern
 	 */
-	@Deprecated
 	@Override
 	public final String getDatePattern(Locale locale)
 	{
-		// TODO this doesn't return a pattern!
-		return DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle).withLocale(locale).toString();
+		String localizedDateTimePattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, IsoChronology.INSTANCE, locale);
+		return localizedDateTimePattern;
 	}
 
 	/**