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:35 UTC
[1/2] wicket git commit: WICKET-6105 Decommission Wicket-Datetime
module
Repository: wicket
Updated Branches:
refs/heads/WICKET-6105-java.time 4da2ef043 -> b82bce9cd
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
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/1b997163
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/1b997163
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/1b997163
Branch: refs/heads/WICKET-6105-java.time
Commit: 1b99716338c149a6701b78cfa1acc25cfa6dd721
Parents: 4da2ef0
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Mar 7 21:36:13 2016 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Mar 7 21:36:13 2016 +0100
----------------------------------------------------------------------
.../markup/html/form/DateTextField.java | 247 --------
.../extensions/yui/calendar/DateField.java | 81 ---
.../extensions/yui/calendar/DateTimeField.html | 26 -
.../extensions/yui/calendar/DateTimeField.java | 617 -------------------
.../ajax/builtin/modal/ModalContent1Page.java | 2 +-
.../ajax/builtin/modal/ModalPanel1.java | 4 +-
.../apache/wicket/examples/dates/DatesPage.java | 2 +-
.../html/form/datetime/DateConverter.java | 10 +-
.../markup/html/form/datetime/DateField.java | 80 +++
.../markup/html/form/datetime/DateLabel.java | 20 +-
.../html/form/datetime/DateTextField.java | 266 ++++++++
.../html/form/datetime/DateTimeField.html | 26 +
.../html/form/datetime/DateTimeField.java | 577 +++++++++++++++++
.../form/datetime/PatternDateConverter.java | 8 +-
.../html/form/datetime/StyleDateConverter.java | 30 +-
.../markup/html/form/datetime/TimeField.java | 71 +++
16 files changed, 1060 insertions(+), 1007 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java
----------------------------------------------------------------------
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java b/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java
deleted file mode 100644
index c2ce854..0000000
--- a/wicket-datetime/src/main/java/org/apache/wicket/datetime/markup/html/form/DateTextField.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * 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.datetime.markup.html.form;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.apache.wicket.datetime.DateConverter;
-import org.apache.wicket.datetime.PatternDateConverter;
-import org.apache.wicket.datetime.StyleDateConverter;
-import org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.convert.IConverter;
-import org.apache.wicket.util.lang.Args;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.format.DateTimeFormat;
-
-/**
- * A TextField that is mapped to a <code>java.util.Date</code> object and that uses Joda time to
- * parse and format values.
- * <p>
- * You should use on of the factory methods to construct the kind you want or use the public
- * constructor and pass in the converter to use.
- * </p>
- * <p>
- * This component tries to apply the time zone difference between the client and server. See the
- * {@link DateConverter#getApplyTimeZoneDifference() date converter} of this package for more
- * information on that.
- * </p>
- *
- * @see StyleDateConverter
- * @see DateTime
- * @see DateTimeFormat
- * @see DateTimeZone
- *
- * @author eelcohillenius
- */
-public class DateTextField extends TextField<Date> implements ITextFormatProvider
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * Creates a new DateTextField defaulting to using a short date pattern
- *
- * @param id
- * The id of the text field
- * @param model
- * The model
- * @param datePattern
- * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available
- * patterns.
- * @return DateTextField
- */
- public static DateTextField forDatePattern(String id, IModel<Date> model, String datePattern)
- {
- return new DateTextField(id, model, new PatternDateConverter(datePattern, true));
- }
-
- /**
- * Creates a new DateTextField defaulting to using a short date pattern
- *
- * @param id
- * The id of the text field
- * @param datePattern
- * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available
- * patterns.
- * @return DateTextField
- */
- public static DateTextField forDatePattern(String id, String datePattern)
- {
- return forDatePattern(id, null, datePattern);
- }
-
- /**
- * Creates a new DateTextField using the provided date style.
- *
- * @param id
- * The id of the text field
- * @param model
- * The model
- * @param dateStyle
- * Date style to use. The first character is the date style, and the second character
- * is the time style. Specify a character of 'S' for short style, 'M' for medium, 'L'
- * for long, and 'F' for full. A date or time may be ommitted by specifying a style
- * character '-'. See {@link DateTimeFormat#forStyle(String)}.
- * @return DateTextField
- */
- public static DateTextField forDateStyle(String id, IModel<Date> model, String dateStyle)
- {
- return new DateTextField(id, model, new StyleDateConverter(dateStyle, true));
- }
-
- /**
- * Creates a new DateTextField using the provided date style.
- *
- * @param id
- * The id of the text field
- * @param dateStyle
- * Date style to use. The first character is the date style, and the second character
- * is the time style. Specify a character of 'S' for short style, 'M' for medium, 'L'
- * for long, and 'F' for full. A date or time may be ommitted by specifying a style
- * character '-'. See {@link DateTimeFormat#forStyle(String)}.
- * @return DateTextField
- */
- public static DateTextField forDateStyle(String id, String dateStyle)
- {
- return forDateStyle(id, null, dateStyle);
- }
-
- /**
- * Creates a new DateTextField defaulting to using a short date pattern
- *
- * @param id
- * The id of the text field
- * @return DateTextField
- */
- public static DateTextField forShortStyle(String id)
- {
- return forShortStyle(id, null, true);
- }
-
- /**
- * Creates a new DateTextField defaulting to using a short date pattern
- *
- * @param id
- * The id of the text field
- * @param model
- * The model
- * @param applyTimeZoneDifference
- * Whether to apply the time zone difference between client and server
- * @return DateTextField
- */
- public static DateTextField forShortStyle(String id, IModel<Date> model,
- boolean applyTimeZoneDifference)
- {
- return new DateTextField(id, model, new StyleDateConverter(applyTimeZoneDifference));
- }
-
- /**
- * Creates a new DateTextField using the provided converter.
- *
- * @param id
- * The id of the text field
- * @param converter
- * the date converter
- * @return DateTextField
- */
- public static DateTextField withConverter(String id, DateConverter converter)
- {
- return withConverter(id, null, converter);
- }
-
- /**
- * Creates a new DateTextField using the provided converter.
- *
- * @param id
- * The id of the text field
- * @param model
- * The model
- * @param converter
- * the date converter
- * @return DateTextField
- */
- public static DateTextField withConverter(String id, IModel<Date> model, DateConverter converter)
- {
- return new DateTextField(id, model, converter);
- }
-
- /**
- * The converter for the TextField
- */
- private final DateConverter converter;
-
- /**
- * Construct with a converter.
- *
- * @param id
- * The component id
- * @param model
- * The model
- * @param converter
- * The converter to use
- */
- public DateTextField(String id, IModel<Date> model, DateConverter converter)
- {
- super(id, model, Date.class);
-
- Args.notNull(converter, "converter");
- this.converter = converter;
- }
-
- /**
- * Construct with a converter, and a null model.
- *
- * @param id
- * The component id
- * @param converter
- * The converter to use
- */
- public DateTextField(String id, DateConverter converter)
- {
- this(id, null, converter);
- }
-
- /**
- * @return The specialized converter.
- * @see org.apache.wicket.Component#getConverter(java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- @Override
- public <C> IConverter<C> getConverter(Class<C> clazz)
- {
- if (Date.class.isAssignableFrom(clazz))
- {
- return (IConverter<C>)converter;
- }
- else
- {
- return super.getConverter(clazz);
- }
- }
-
- /**
- * @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat()
- */
- @Override
- public final String getTextFormat()
- {
- return converter.getDatePattern(getLocale());
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java
----------------------------------------------------------------------
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java
deleted file mode 100644
index 5c08241..0000000
--- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.yui.calendar;
-
-import java.util.Date;
-
-import org.apache.wicket.datetime.markup.html.form.DateTextField;
-import org.apache.wicket.model.IModel;
-
-/**
- * Works on a {@link java.util.Date} object. Displays a {@link DateTextField} and a
- * {@link DatePicker calendar popup}.<br/>
- * <p>
- * Note: {@link DateField} must <strong>not</strong> be associated with an
- * <code><input></code> tag, as opposed to {@link DateTextField}! The corresponding tag is
- * typically either a <code><div></code> or a <code><span></code> tag.
- * </p>
- *
- * Example:
- * <p>
- * <u>Java:</u>
- *
- * <pre>
- * DateField dateField = new DateField("birthday");
- * </pre>
- *
- * </p>
- * <p>
- * <u>Markup:</u>
- *
- * <pre>
- * <div wicket:id="birthday"></div>
- * </pre>
- *
- * </p>
- *
- * @author eelcohillenius
- */
-public class DateField extends DateTimeField
-{
- private static final long serialVersionUID = 1L;
-
- /**
- * Construct.
- *
- * @param id
- */
- public DateField(String id)
- {
- this(id, null);
- }
-
- /**
- * Construct.
- *
- * @param id
- * @param model
- */
- public DateField(String id, IModel<Date> model)
- {
- super(id, model);
-
- get(HOURS).setVisibilityAllowed(false);
- get(MINUTES).setVisibilityAllowed(false);
- get(AM_OR_PM_CHOICE).setVisibilityAllowed(false);
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html
----------------------------------------------------------------------
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html
deleted file mode 100644
index c714db3..0000000
--- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- 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.
--->
-<wicket:panel xmlns:wicket="http://wicket.apache.org">
- <span style="white-space: nowrap;">
- <input type="text" wicket:id="date" size="12" />
- <input type="text" wicket:id="hours" size="2" maxlength="2" />
- <span wicket:id="hoursSeparator"> :</span>
- <input type="text" wicket:id="minutes" size="2" maxlength="2" />
- <select wicket:id="amOrPmChoice"></select>
- </span>
-</wicket:panel>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java
----------------------------------------------------------------------
diff --git a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java b/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java
deleted file mode 100644
index 83c7a60..0000000
--- a/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java
+++ /dev/null
@@ -1,617 +0,0 @@
-/*
- * 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.yui.calendar;
-
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Map;
-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.datetime.markup.html.form.DateTextField;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.FormComponentPanel;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-import org.apache.wicket.model.PropertyModel;
-import org.apache.wicket.protocol.http.request.WebClientInfo;
-import org.apache.wicket.util.convert.IConverter;
-import org.apache.wicket.util.convert.converter.IntegerConverter;
-import org.apache.wicket.validation.validator.RangeValidator;
-import org.joda.time.DateTimeFieldType;
-import org.joda.time.DateTimeZone;
-import org.joda.time.MutableDateTime;
-import org.joda.time.format.DateTimeFormat;
-
-/**
- * Works on a {@link java.util.Date} object. Displays a date field and a {@link 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 DateTextField} by overriding {@link #newDateTextField(String, PropertyModel)} and calling
- * {@link #processInput()}:
- *
- * <pre>
- * DateTimeField dateTimeField = new DateTimeField(...) {
- * protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
- * {
- * DateTextField dateField = super.newDateTextField(id, dateFieldModel);
- * dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
- * 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<Date>
-{
- /**
- * Enumerated type for different ways of handling the render part of requests.
- */
- public static enum AM_PM {
- /** */
- AM("AM"),
-
- /** */
- PM("PM");
-
- /** */
- private String value;
-
- AM_PM(final String name)
- {
- value = name;
- }
-
- /**
- * @see java.lang.Enum#toString()
- */
- @Override
- public String toString()
- {
- return value;
- }
- }
-
- private static final long serialVersionUID = 1L;
-
- // Component-IDs
- 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";
-
- // PropertyModel string to access getAmOrPm
- private static final String AM_OR_PM = "amOrPm";
-
- private static final IConverter<Integer> MINUTES_CONVERTER = new IntegerConverter() {
- protected NumberFormat newNumberFormat(Locale locale) {
- return new DecimalFormat("00");
- }
- };
-
- // The dropdown list for AM/PM and it's associated model object
- private DropDownChoice<AM_PM> amOrPmChoice;
- private AM_PM amOrPm = AM_PM.AM;
-
- // The date TextField and it's associated model object
- // Note that any time information in date will be ignored
- private DateTextField dateField;
- private Date date;
-
- // The TextField for "hours" and it's associated model object
- private TextField<Integer> hoursField;
- private Integer hours;
-
- // The TextField for "minutes" and it's associated model object
- private TextField<Integer> minutesField;
- private Integer minutes;
-
- /**
- * Construct.
- *
- * @param id
- */
- public DateTimeField(final String id)
- {
- this(id, null);
- }
-
- /**
- * Construct.
- *
- * @param id
- * @param model
- */
- public DateTimeField(final String id, final IModel<Date> model)
- {
- super(id, model);
-
- // Sets the type that will be used when updating the model for this component.
- setType(Date.class);
-
- // Create and add the date TextField
- PropertyModel<Date> dateFieldModel = new PropertyModel<>(this, DATE);
- add(dateField = newDateTextField(DATE, dateFieldModel));
-
- // Add a date picker to the date TextField
- dateField.add(newDatePicker());
-
- // Create and add the "hours" TextField
- add(hoursField = newHoursTextField(HOURS, new PropertyModel<Integer>(this, HOURS),
- Integer.class));
-
- // Create and add the "minutes" TextField
- add(minutesField = newMinutesTextField(MINUTES, new PropertyModel<Integer>(this, MINUTES),
- Integer.class));
-
- // Create and add the "AM/PM" Listbox
- add(amOrPmChoice = new DropDownChoice<AM_PM>(AM_OR_PM_CHOICE, new PropertyModel<AM_PM>(
- this, AM_OR_PM), Arrays.asList(AM_PM.values())));
-
- add(new WebMarkupContainer("hoursSeparator")
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public boolean isVisible()
- {
- return minutesField.determineVisibility();
- }
- });
- }
-
- /**
- * create a new {@link TextField} instance for hours to be added to this panel.
- *
- * @param id
- * the component id
- * @param model
- * model that should be used by the {@link TextField}
- * @param type
- * the type of the text field
- * @return a new text field instance
- */
- protected TextField<Integer> newHoursTextField(final String id, IModel<Integer> model, Class<Integer> type) {
- TextField<Integer> hoursTextField = new TextField<>(id, model, type);
- hoursTextField.add(getMaximumHours() == 24 ? RangeValidator.range(0, 23) : RangeValidator
- .range(1, 12));
- hoursTextField.setLabel(new Model<>(HOURS));
- return hoursTextField;
- }
-
- /**
- * create a new {@link TextField} instance for minutes to be added to this panel.
- *
- * @param id
- * the component id
- * @param model
- * model that should be used by the {@link TextField}
- * @param type
- * the type of the text field
- * @return a new text field instance
- */
- protected TextField<Integer> newMinutesTextField(final String id, IModel<Integer> model,
- Class<Integer> type)
- {
- TextField<Integer> minutesField = new TextField<Integer>(id, model, type)
- {
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings("unchecked")
- @Override
- public <C> IConverter<C> getConverter(Class<C> type)
- {
- if (Integer.class.isAssignableFrom(type))
- {
- return (IConverter<C>)MINUTES_CONVERTER;
- }
- else
- {
- return super.getConverter(type);
- }
- }
- };
- minutesField.add(new RangeValidator<>(0, 59));
- minutesField.setLabel(new Model<>(MINUTES));
- return minutesField;
- }
-
- /**
- *
- * @return The date TextField
- */
- protected final DateTextField getDateTextField()
- {
- return dateField;
- }
-
- /**
- * Gets the amOrPm model object of the drop down choice.
- *
- * @return amOrPm
- *
- * @deprecated valid during rendering only
- */
- public final AM_PM getAmOrPm()
- {
- return amOrPm;
- }
-
- /**
- * Gets the date model object for the date TextField. Any associated time information will be
- * ignored.
- *
- * @return date
- *
- * @deprecated valid during rendering only
- */
- public final Date getDate()
- {
- return date;
- }
-
- /**
- * Gets the hours model object for the TextField
- *
- * @return hours
- *
- * @deprecated valid during rendering only
- */
- public final Integer getHours()
- {
- return hours;
- }
-
- /**
- * Gets the minutes model object for the TextField
- *
- * @return minutes
- *
- * @deprecated valid during rendering only
- */
- public final Integer getMinutes()
- {
- return minutes;
- }
-
- /**
- * Gives overriding classes the option of adding (or even changing/ removing) configuration
- * properties for the javascript widget. See <a
- * href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for the
- * available options. If you want to override/ remove properties, you should call
- * super.configure(properties) first. If you don't call that, be aware that you will have to
- * call {@link #configure(java.util.Map)} manually if you like localized strings to be added.
- *
- * @param widgetProperties
- * the current widget properties
- */
- protected void configure(Map<String, Object> widgetProperties)
- {
- }
-
- @Override
- public String getInput()
- {
- // since we override convertInput, we can let this method return a value
- // that is just suitable for error reporting
- return dateField.getInput() + ", " + hoursField.getInput() + ":" + minutesField.getInput();
- }
-
- /**
- * Sets the amOrPm model object associated with the drop down choice.
- *
- * @param amOrPm
- * amOrPm
- */
- public final void setAmOrPm(final AM_PM amOrPm)
- {
- this.amOrPm = amOrPm;
- }
-
- /**
- * Sets the date model object associated with the date TextField. It does not affect hours or
- * minutes.
- *
- * @param date
- * date
- */
- public final void setDate(final Date date)
- {
- this.date = date;
- }
-
- /**
- * Sets hours.
- *
- * @param hours
- * hours
- */
- public final void setHours(final Integer hours)
- {
- this.hours = hours;
- }
-
- /**
- * Sets minutes.
- *
- * @param minutes
- * minutes
- */
- public final void setMinutes(final Integer minutes)
- {
- this.minutes = minutes;
- }
-
- /**
- * Gets the client's time zone.
- *
- * @return The client's time zone or null
- */
- protected TimeZone getClientTimeZone()
- {
- ClientInfo info = Session.get().getClientInfo();
- if (info instanceof WebClientInfo)
- {
- return ((WebClientInfo)info).getProperties().getTimeZone();
- }
- 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
- Date dateFieldInput = dateField.getConvertedInput();
- Integer hoursInput = hoursField.getConvertedInput();
- Integer minutesInput = minutesField.getConvertedInput();
- AM_PM amOrPmInput = amOrPmChoice.getConvertedInput();
-
- if (dateFieldInput == null)
- {
- return;
- }
-
- // Get year, month and day ignoring any timezone of the Date object
- Calendar cal = Calendar.getInstance();
- cal.setTime(dateFieldInput);
- int year = cal.get(Calendar.YEAR);
- int month = cal.get(Calendar.MONTH) + 1;
- int day = cal.get(Calendar.DAY_OF_MONTH);
- int hours = (hoursInput == null ? 0 : hoursInput % 24);
- int minutes = (minutesInput == null ? 0 : minutesInput);
-
- // Use the input to create a date object with proper timezone
- MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0,
- DateTimeZone.forTimeZone(getClientTimeZone()));
-
- // Adjust for halfday if needed
- if (use12HourFormat())
- {
- int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0);
- date.set(DateTimeFieldType.halfdayOfDay(), halfday);
- date.set(DateTimeFieldType.hourOfHalfday(), hours % 12);
- }
-
- // The date will be in the server's timezone
- setConvertedInput(newDateInstance(date.getMillis()));
- }
- catch (RuntimeException e)
- {
- DateTimeField.this.error(e.getMessage());
- invalid();
- }
- }
-
- /**
- * A factory method for the DateTextField's model object.
- *
- * @return any specialization of java.util.Date
- */
- protected Date newDateInstance()
- {
- return new Date();
- }
-
- /**
- * A factory method for the DateTextField's model object.
- *
- * @param time
- * the time in milliseconds
- * @return any specialization of java.util.Date
- */
- protected Date newDateInstance(long time)
- {
- return new Date(time);
- }
-
- /**
- * create a new {@link DateTextField} instance to be added to this panel.
- *
- * @param id
- * the component id
- * @param dateFieldModel
- * model that should be used by the {@link DateTextField}
- * @return a new date text field instance
- */
- protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
- {
- return DateTextField.forShortStyle(id, dateFieldModel, false);
- }
-
- /**
- * @see org.apache.wicket.Component#onBeforeRender()
- */
- @Override
- protected void onBeforeRender()
- {
- dateField.setRequired(isRequired());
- hoursField.setRequired(isRequired());
- minutesField.setRequired(isRequired());
-
- boolean use12HourFormat = use12HourFormat();
- amOrPmChoice.setVisible(use12HourFormat);
-
- Date modelObject = (Date)getDefaultModelObject();
- if (modelObject == null)
- {
- date = null;
- hours = null;
- minutes = null;
- }
- else
- {
- MutableDateTime mDate = new MutableDateTime(modelObject);
- // convert date to the client's time zone if we have that info
- TimeZone zone = getClientTimeZone();
- if (zone != null)
- {
- mDate.setZone(DateTimeZone.forTimeZone(zone));
- }
-
- date = mDate.toDateTime().toLocalDate().toDate();
-
- if (use12HourFormat)
- {
- int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday());
- hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay;
- }
- else
- {
- hours = mDate.get(DateTimeFieldType.hourOfDay());
- }
-
- amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM;
- minutes = mDate.getMinuteOfHour();
- }
-
- super.onBeforeRender();
- }
-
- /**
- * Change a date in another timezone
- *
- * @param date
- * The input date.
- * @param zone
- * The target timezone.
- * @return A new converted date.
- */
- public static Date changeTimeZone(Date date, TimeZone zone)
- {
- Calendar first = Calendar.getInstance(zone);
- first.setTimeInMillis(date.getTime());
-
- Calendar output = Calendar.getInstance();
- output.set(Calendar.YEAR, first.get(Calendar.YEAR));
- output.set(Calendar.MONTH, first.get(Calendar.MONTH));
- output.set(Calendar.DAY_OF_MONTH, first.get(Calendar.DAY_OF_MONTH));
- output.set(Calendar.HOUR_OF_DAY, first.get(Calendar.HOUR_OF_DAY));
- output.set(Calendar.MINUTE, first.get(Calendar.MINUTE));
- output.set(Calendar.SECOND, first.get(Calendar.SECOND));
- output.set(Calendar.MILLISECOND, first.get(Calendar.MILLISECOND));
-
- return output.getTime();
- }
-
- /**
- * Checks whether the current {@link Locale} uses the 12h or 24h time format. This method can be
- * overridden to e.g. always use 24h format.
- *
- * @return true, if the current {@link Locale} uses the 12h format.<br/>
- * false, otherwise
- */
- protected boolean use12HourFormat()
- {
- String pattern = DateTimeFormat.patternForStyle("-S", getLocale());
- return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1
- || pattern.indexOf('K') != -1;
- }
-
- /**
- * @return either 12 or 24, depending on the hour format of the current {@link Locale}
- */
- private int getMaximumHours()
- {
- return getMaximumHours(use12HourFormat());
- }
-
- /**
- * Convenience method (mainly for optimization purposes), in case {@link #use12HourFormat()} has
- * already been stored in a local variable and thus doesn't need to be computed again.
- *
- * @param use12HourFormat
- * the hour format to use
- * @return either 12 or 24, depending on the parameter <code>use12HourFormat</code>
- */
- private int getMaximumHours(boolean use12HourFormat)
- {
- return use12HourFormat ? 12 : 24;
- }
-
- /**
- * The DatePicker that gets added to the DateTimeField component. Users may override this method
- * with a DatePicker of their choice.
- *
- * @return a new {@link DatePicker} instance
- */
- protected DatePicker newDatePicker()
- {
- return new DatePicker()
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void configure(final Map<String, Object> widgetProperties,
- final IHeaderResponse response, final Map<String, Object> initVariables)
- {
- super.configure(widgetProperties, response, initVariables);
-
- DateTimeField.this.configure(widgetProperties);
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java
index d0c3f3f..8604e97 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java
@@ -21,7 +21,7 @@ import org.apache.wicket.PageReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
-import org.apache.wicket.extensions.yui.calendar.DateTimeField;
+import org.apache.wicket.extensions.markup.html.form.datetime.DateTimeField;
import org.apache.wicket.markup.html.WebPage;
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java
index 6a5f5ab..ec7bae6 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java
@@ -18,7 +18,7 @@ package org.apache.wicket.examples.ajax.builtin.modal;
import java.util.Map;
-import org.apache.wicket.extensions.yui.calendar.DateTimeField;
+import org.apache.wicket.extensions.markup.html.form.datetime.DateTimeField;
import org.apache.wicket.markup.html.panel.Panel;
/**
@@ -37,7 +37,7 @@ public class ModalPanel1 extends Panel
add(new DateTimeField("dateTimeField")
{
/**
- * @see org.apache.wicket.extensions.yui.calendar.DateTimeField#configure(java.util.Map)
+ * @see DateTimeField#configure(java.util.Map)
*/
@Override
protected void configure(Map<String, Object> widgetProperties)
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java
index 26576d6..4392342 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java
@@ -29,7 +29,7 @@ import org.apache.wicket.extensions.markup.html.form.datetime.StyleDateConverter
import org.apache.wicket.datetime.markup.html.form.DateTextField;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
-import org.apache.wicket.extensions.yui.calendar.DateTimeField;
+import org.apache.wicket.extensions.markup.html.form.datetime.DateTimeField;
import org.apache.wicket.extensions.yui.calendar.TimeField;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateConverter.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateConverter.java
index b7284f2..ce9f6f2 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateConverter.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateConverter.java
@@ -27,6 +27,7 @@ import org.apache.wicket.core.request.ClientInfo;
import org.apache.wicket.protocol.http.request.WebClientInfo;
import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;
+import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.string.Strings;
@@ -64,10 +65,6 @@ public abstract class DateConverter implements IConverter<ZonedDateTime>
this.applyTimeZoneDifference = applyTimeZoneDifference;
}
- /**
- * @see org.apache.wicket.util.convert.IConverter#convertToObject(java.lang.String,
- * java.util.Locale)
- */
@Override
public ZonedDateTime convertToObject(String value, Locale locale)
{
@@ -77,10 +74,7 @@ public abstract class DateConverter implements IConverter<ZonedDateTime>
}
DateTimeFormatter format = getFormat(locale);
- if (format == null)
- {
- throw new IllegalStateException("format must be not null");
- }
+ Args.notNull(format, "format");
if (applyTimeZoneDifference)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateField.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateField.java
new file mode 100644
index 0000000..27a6a25
--- /dev/null
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateField.java
@@ -0,0 +1,80 @@
+/*
+ * 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.ZonedDateTime;
+
+import org.apache.wicket.model.IModel;
+
+/**
+ * Works on a {@link java.util.Date} object. Displays a {@link DateTextField} and a
+ * {@link DatePicker calendar popup}.<br/>
+ * <p>
+ * Note: {@link DateField} must <strong>not</strong> be associated with an
+ * <code><input></code> tag, as opposed to {@link DateTextField}! The corresponding tag is
+ * typically either a <code><div></code> or a <code><span></code> tag.
+ * </p>
+ *
+ * Example:
+ * <p>
+ * <u>Java:</u>
+ *
+ * <pre>
+ * DateField dateField = new DateField("birthday");
+ * </pre>
+ *
+ * </p>
+ * <p>
+ * <u>Markup:</u>
+ *
+ * <pre>
+ * <div wicket:id="birthday"></div>
+ * </pre>
+ *
+ * </p>
+ *
+ * @author eelcohillenius
+ */
+public class DateField extends DateTimeField
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ *
+ * @param id
+ */
+ public DateField(String id)
+ {
+ this(id, null);
+ }
+
+ /**
+ * Construct.
+ *
+ * @param id
+ * @param model
+ */
+ public DateField(String id, IModel<ZonedDateTime> model)
+ {
+ super(id, model);
+
+ get(HOURS).setVisibilityAllowed(false);
+ get(MINUTES).setVisibilityAllowed(false);
+ get(AM_OR_PM_CHOICE).setVisibilityAllowed(false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java
index c84e768..6e39c3e 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateLabel.java
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.extensions.markup.html.form.datetime;
+import java.time.LocalDate;
import java.time.format.FormatStyle;
import java.util.Date;
@@ -25,6 +26,7 @@ import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.convert.IConverter;
+import org.apache.wicket.util.lang.Args;
/**
@@ -60,7 +62,7 @@ public class DateLabel extends Label implements IGenericComponent<Date>
*
* @see org.apache.wicket.markup.html.form.TextField
*/
- public static DateLabel forDatePattern(String id, IModel<Date> model, String datePattern)
+ public static DateLabel forDatePattern(String id, IModel<LocalDate> model, String datePattern)
{
return new DateLabel(id, model, new PatternDateConverter(datePattern, true));
}
@@ -95,9 +97,9 @@ public class DateLabel extends Label implements IGenericComponent<Date>
*
* @see org.apache.wicket.markup.html.form.TextField
*/
- public static DateLabel forDateStyle(String id, IModel<Date> model, FormatStyle dateStyle)
+ public static DateLabel forDateStyle(String id, IModel<LocalDate> model, FormatStyle dateStyle)
{
- return new DateLabel(id, model, new StyleDateConverter(dateStyle, true));
+ return new DateLabel(id, model, new StyleDateConverter(dateStyle, null, true));
}
/**
@@ -141,7 +143,7 @@ public class DateLabel extends Label implements IGenericComponent<Date>
*
* @see org.apache.wicket.markup.html.form.TextField
*/
- public static DateLabel forShortStyle(String id, IModel<Date> model)
+ public static DateLabel forShortStyle(String id, IModel<LocalDate> model)
{
return new DateLabel(id, model, new StyleDateConverter(true));
}
@@ -175,7 +177,7 @@ public class DateLabel extends Label implements IGenericComponent<Date>
*
* @see org.apache.wicket.markup.html.form.TextField
*/
- public static DateLabel withConverter(String id, IModel<Date> model, DateConverter converter)
+ public static DateLabel withConverter(String id, IModel<LocalDate> model, DateConverter converter)
{
return new DateLabel(id, model, converter);
}
@@ -214,14 +216,10 @@ public class DateLabel extends Label implements IGenericComponent<Date>
* @param converter
* The converter to use
*/
- public DateLabel(String id, IModel<Date> model, DateConverter converter)
+ public DateLabel(String id, IModel<LocalDate> model, DateConverter converter)
{
super(id, model);
- if (converter == null)
- {
- throw new IllegalStateException("converter may not be null");
- }
- this.converter = converter;
+ this.converter = Args.notNull(converter, "converter");
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTextField.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTextField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTextField.java
new file mode 100644
index 0000000..070ab58
--- /dev/null
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTextField.java
@@ -0,0 +1,266 @@
+/*
+ * 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.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.FormatStyle;
+import java.util.Date;
+
+import org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.convert.IConverter;
+import org.apache.wicket.util.lang.Args;
+
+/**
+ * A TextField that is mapped to a <code>java.util.Date</code> object and that uses Joda time to
+ * parse and format values.
+ * <p>
+ * You should use on of the factory methods to construct the kind you want or use the public
+ * constructor and pass in the converter to use.
+ * </p>
+ * <p>
+ * This component tries to apply the time zone difference between the client and server. See the
+ * {@link DateConverter#getApplyTimeZoneDifference() date converter} of this package for more
+ * information on that.
+ * </p>
+ *
+ * @see StyleDateConverter
+ * @see java.time.ZonedDateTime
+ * @see java.time.format.DateTimeFormatter
+ * @see java.time.ZoneId
+ *
+ * @author eelcohillenius
+ */
+public class DateTextField extends TextField<LocalDate> implements ITextFormatProvider
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new DateTextField defaulting to using a short date pattern
+ *
+ * @param id
+ * The id of the text field
+ * @param model
+ * The model
+ * @param datePattern
+ * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available
+ * patterns.
+ * @return DateTextField
+ */
+ public static DateTextField forDatePattern(String id, IModel<LocalDate> model, String datePattern)
+ {
+ return new DateTextField(id, model, new PatternDateConverter(datePattern, true));
+ }
+
+ /**
+ * Creates a new DateTextField defaulting to using a short date pattern
+ *
+ * @param id
+ * The id of the text field
+ * @param datePattern
+ * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available
+ * patterns.
+ * @return DateTextField
+ */
+ public static DateTextField forDatePattern(String id, String datePattern)
+ {
+ return forDatePattern(id, null, datePattern);
+ }
+
+ /**
+ * Creates a new DateTextField using the provided date style.
+ *
+ * @param id
+ * The id of the text field
+ * @param model
+ * The model
+ * @param dateStyle
+ * Date style to use. The first character is the date style, and the second character
+ * is the time style. Specify a character of 'S' for short style, 'M' for medium, 'L'
+ * for long, and 'F' for full. A date or time may be ommitted by specifying a style
+ * character '-'. See {@link org.joda.time.DateTimeFormat#forStyle(String)}.
+ * @return DateTextField
+ */
+ public static DateTextField forDateStyle(String id, IModel<LocalDate> model, String dateStyle)
+ {
+ FormatStyle dateFormatStyle = parseFormatStyle(dateStyle.charAt(0));
+ return forDateStyle(id, model, dateFormatStyle, null);
+ }
+
+ public static DateTextField forDateStyle(String id, IModel<LocalDate> model, FormatStyle dateStyle, FormatStyle timeStyle)
+ {
+ return new DateTextField(id, model, new StyleDateConverter(dateStyle, timeStyle, true));
+ }
+
+ /**
+ * Creates a new DateTextField using the provided date style.
+ *
+ * @param id
+ * The id of the text field
+ * @param dateStyle
+ * Date style to use. The first character is the date style, and the second character
+ * is the time style. Specify a character of 'S' for short style, 'M' for medium, 'L'
+ * for long, and 'F' for full. A date or time may be ommitted by specifying a style
+ * character '-'. See {@link org.joda.time.DateTimeFormat#forStyle(String)}.
+ * @return DateTextField
+ */
+ public static DateTextField forDateStyle(String id, String dateStyle)
+ {
+ return forDateStyle(id, null, dateStyle);
+ }
+
+ /**
+ * Creates a new DateTextField defaulting to using a short date pattern
+ *
+ * @param id
+ * The id of the text field
+ * @return DateTextField
+ */
+ public static DateTextField forShortStyle(String id)
+ {
+ return forShortStyle(id, null, true);
+ }
+
+ /**
+ * Creates a new DateTextField defaulting to using a short date pattern
+ *
+ * @param id
+ * The id of the text field
+ * @param model
+ * The model
+ * @param applyTimeZoneDifference
+ * Whether to apply the time zone difference between client and server
+ * @return DateTextField
+ */
+ public static DateTextField forShortStyle(String id, IModel<LocalDate> model,
+ boolean applyTimeZoneDifference)
+ {
+ return new DateTextField(id, model, new StyleDateConverter(applyTimeZoneDifference));
+ }
+
+ /**
+ * Creates a new DateTextField using the provided converter.
+ *
+ * @param id
+ * The id of the text field
+ * @param converter
+ * the date converter
+ * @return DateTextField
+ */
+ public static DateTextField withConverter(String id, DateConverter converter)
+ {
+ return withConverter(id, null, converter);
+ }
+
+ /**
+ * Creates a new DateTextField using the provided converter.
+ *
+ * @param id
+ * The id of the text field
+ * @param model
+ * The model
+ * @param converter
+ * the date converter
+ * @return DateTextField
+ */
+ public static DateTextField withConverter(String id, IModel<LocalDate> model, DateConverter converter)
+ {
+ return new DateTextField(id, model, converter);
+ }
+
+ /**
+ * The converter for the TextField
+ */
+ private final DateConverter converter;
+
+ /**
+ * Construct with a converter.
+ *
+ * @param id
+ * The component id
+ * @param model
+ * The model
+ * @param converter
+ * The converter to use
+ */
+ public DateTextField(String id, IModel<LocalDate> model, DateConverter converter)
+ {
+ super(id, model, LocalDate.class);
+
+ Args.notNull(converter, "converter");
+ this.converter = converter;
+ }
+
+ /**
+ * Construct with a converter, and a null model.
+ *
+ * @param id
+ * The component id
+ * @param converter
+ * The converter to use
+ */
+ public DateTextField(String id, DateConverter converter)
+ {
+ this(id, null, converter);
+ }
+
+ /**
+ * @return The specialized converter.
+ * @see org.apache.wicket.Component#getConverter(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C> IConverter<C> getConverter(Class<C> clazz)
+ {
+ if (Date.class.isAssignableFrom(clazz))
+ {
+ return (IConverter<C>)converter;
+ }
+ else
+ {
+ return super.getConverter(clazz);
+ }
+ }
+
+ /**
+ * @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat()
+ */
+ @Override
+ public final String getTextFormat()
+ {
+ return converter.getDatePattern(getLocale());
+ }
+
+ public static FormatStyle parseFormatStyle(char style)
+ {
+ switch (style)
+ {
+ case 'S':
+ return FormatStyle.SHORT;
+ case 'M':
+ return FormatStyle.MEDIUM;
+ case 'L':
+ return FormatStyle.LONG;
+ case 'F':
+ return FormatStyle.FULL;
+ default:
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.html
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.html b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.html
new file mode 100644
index 0000000..c714db3
--- /dev/null
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.html
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ 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.
+-->
+<wicket:panel xmlns:wicket="http://wicket.apache.org">
+ <span style="white-space: nowrap;">
+ <input type="text" wicket:id="date" size="12" />
+ <input type="text" wicket:id="hours" size="2" maxlength="2" />
+ <span wicket:id="hoursSeparator"> :</span>
+ <input type="text" wicket:id="minutes" size="2" maxlength="2" />
+ <select wicket:id="amOrPmChoice"></select>
+ </span>
+</wicket:panel>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/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
new file mode 100644
index 0000000..82142f0
--- /dev/null
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java
@@ -0,0 +1,577 @@
+/*
+ * 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.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.temporal.ChronoField;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TimeZone;
+
+import javafx.scene.control.DatePicker;
+
+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.WebMarkupContainer;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.FormComponentPanel;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.util.convert.IConverter;
+import org.apache.wicket.util.convert.converter.IntegerConverter;
+import org.apache.wicket.validation.validator.RangeValidator;
+
+/**
+ * Works on a {@link java.util.Date} object. Displays a date field and a {@link 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 DateTextField} by overriding {@link #newDateTextField(String, PropertyModel)} and calling
+ * {@link #processInput()}:
+ *
+ * <pre>
+ * DateTimeField dateTimeField = new DateTimeField(...) {
+ * protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel)
+ * {
+ * DateTextField dateField = super.newDateTextField(id, dateFieldModel);
+ * dateField.add(new AjaxFormComponentUpdatingBehavior("change") {
+ * 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>
+{
+ /**
+ * Enumerated type for different ways of handling the render part of requests.
+ */
+ public enum AM_PM {
+ /** */
+ AM("AM"),
+
+ /** */
+ PM("PM");
+
+ private final String value;
+
+ AM_PM(final String name)
+ {
+ value = name;
+ }
+
+ @Override
+ public String toString()
+ {
+ return value;
+ }
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ // Component-IDs
+ protected static final String DATE = "hours";
+ protected static final String HOURS = "hours";
+ protected static final String MINUTES = "minutes";
+ protected static final String AM_OR_PM_CHOICE = "amOrPmChoice";
+
+ // PropertyModel string to access getAmOrPm
+ private static final String AM_OR_PM = "amOrPm";
+
+ private static final IConverter<Integer> MINUTES_CONVERTER = new IntegerConverter() {
+ protected NumberFormat newNumberFormat(Locale locale) {
+ return new DecimalFormat("00");
+ }
+ };
+
+ // The dropdown list for AM/PM and it's associated model object
+ private DropDownChoice<AM_PM> amOrPmChoice;
+ private AM_PM amOrPm = AM_PM.AM;
+
+ // 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;
+
+ // The TextField for "hours" and it's associated model object
+ private TextField<Integer> hoursField;
+
+ // The TextField for "minutes" and it's associated model object
+ private TextField<Integer> minutesField;
+
+ /**
+ * 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(Date.class);
+
+ // Create and add the date TextField
+ PropertyModel<LocalDate> dateFieldModel = new PropertyModel<>(this, DATE);
+ add(dateField = newDateTextField(DATE, dateFieldModel));
+
+ // Add a date picker to the date TextField
+// dateField.add(newDatePicker());
+
+ // Create and add the "hours" TextField
+ add(hoursField = newHoursTextField(HOURS, new HoursModel(), Integer.class));
+
+ // Create and add the "minutes" TextField
+ add(minutesField = newMinutesTextField(MINUTES, new MinutesModel(), Integer.class));
+
+ // Create and add the "AM/PM" Listbox
+ add(amOrPmChoice = new DropDownChoice<>(AM_OR_PM_CHOICE, new AmPmModel(), Arrays.asList(AM_PM.values())));
+
+ add(new WebMarkupContainer("hoursSeparator")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean isVisible()
+ {
+ return minutesField.determineVisibility();
+ }
+ });
+ }
+
+ /**
+ * create a new {@link TextField} instance for hours to be added to this panel.
+ *
+ * @param id
+ * the component id
+ * @param model
+ * model that should be used by the {@link TextField}
+ * @param type
+ * the type of the text field
+ * @return a new text field instance
+ */
+ protected TextField<Integer> newHoursTextField(final String id, IModel<Integer> model, Class<Integer> type) {
+ TextField<Integer> hoursTextField = new TextField<>(id, model, type);
+ hoursTextField.add(getMaximumHours() == 24 ? RangeValidator.range(0, 23) : RangeValidator
+ .range(1, 12));
+ hoursTextField.setLabel(new Model<>(HOURS));
+ return hoursTextField;
+ }
+
+ /**
+ * create a new {@link TextField} instance for minutes to be added to this panel.
+ *
+ * @param id
+ * the component id
+ * @param model
+ * model that should be used by the {@link TextField}
+ * @param type
+ * the type of the text field
+ * @return a new text field instance
+ */
+ protected TextField<Integer> newMinutesTextField(final String id, IModel<Integer> model,
+ Class<Integer> type)
+ {
+ TextField<Integer> minutesField = new TextField<Integer>(id, model, type)
+ {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C> IConverter<C> getConverter(Class<C> type)
+ {
+ if (Integer.class.isAssignableFrom(type))
+ {
+ return (IConverter<C>)MINUTES_CONVERTER;
+ }
+ else
+ {
+ return super.getConverter(type);
+ }
+ }
+ };
+ minutesField.add(new RangeValidator<>(0, 59));
+ minutesField.setLabel(new Model<>(MINUTES));
+ return minutesField;
+ }
+
+ /**
+ *
+ * @return The date TextField
+ */
+ protected final DateTextField getDateTextField()
+ {
+ return dateField;
+ }
+
+ /**
+ * Gets the amOrPm model object of the drop down choice.
+ *
+ * @return amOrPm
+ *
+ * @deprecated valid during rendering only
+ */
+ public final AM_PM getAmOrPm()
+ {
+ return amOrPm;
+ }
+
+ /**
+ * Gives overriding classes the option of adding (or even changing/ removing) configuration
+ * properties for the javascript widget. See <a
+ * href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for the
+ * available options. If you want to override/ remove properties, you should call
+ * super.configure(properties) first. If you don't call that, be aware that you will have to
+ * call {@link #configure(java.util.Map)} manually if you like localized strings to be added.
+ *
+ * @param widgetProperties
+ * the current widget properties
+ */
+ protected void configure(Map<String, Object> widgetProperties)
+ {
+ }
+
+ @Override
+ public String getInput()
+ {
+ // since we override convertInput, we can let this method return a value
+ // that is just suitable for error reporting
+ return dateField.getInput() + ", " + hoursField.getInput() + ":" + minutesField.getInput();
+ }
+
+ /**
+ * Sets the amOrPm model object associated with the drop down choice.
+ *
+ * @param amOrPm
+ * amOrPm
+ */
+ public final void setAmOrPm(final AM_PM amOrPm)
+ {
+ this.amOrPm = amOrPm;
+ }
+
+ /**
+ * 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.toZoneId();
+ }
+ 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 dateFieldInput = dateField.getConvertedInput();
+ Integer hoursInput = hoursField.getConvertedInput();
+ Integer minutesInput = minutesField.getConvertedInput();
+ AM_PM amOrPmInput = amOrPmChoice.getConvertedInput();
+
+ if (dateFieldInput == null)
+ {
+ return;
+ }
+
+ // Use the input to create a date object with proper timezone
+ LocalTime localTime = LocalTime.of(hoursInput, minutesInput);
+ ZonedDateTime date = ZonedDateTime.of(dateFieldInput, localTime, getClientTimeZone());
+
+ // Adjust for halfday if needed
+ if (use12HourFormat())
+ {
+ int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0);
+ date = date.with(ChronoField.AMPM_OF_DAY, halfday);
+// date = date.with(ChronoField.HOUR_OF_AMPM, hours % 12);
+ }
+
+ // The date will be in the server's timezone
+ setConvertedInput(date);
+ }
+ catch (RuntimeException e)
+ {
+ DateTimeField.this.error(e.getMessage());
+ invalid();
+ }
+ }
+
+ /**
+ * A factory method for the DateTextField's model object.
+ *
+ * @return any specialization of java.util.Date
+ */
+ protected LocalDate newDateInstance()
+ {
+ return LocalDate.now();
+ }
+
+ /**
+ * A factory method for the DateTextField's model object.
+ *
+ * @param time
+ * the time in milliseconds
+ * @return any specialization of java.util.Date
+ */
+ protected Date newDateInstance(long time)
+ {
+ return new Date(time);
+ }
+
+ /**
+ * create a new {@link DateTextField} instance to be added to this panel.
+ *
+ * @param id
+ * the component id
+ * @param dateFieldModel
+ * model that should be used by the {@link DateTextField}
+ * @return a new date text field instance
+ */
+ protected DateTextField newDateTextField(String id, PropertyModel<LocalDate> dateFieldModel)
+ {
+ return DateTextField.forShortStyle(id, dateFieldModel, false);
+ }
+
+ /**
+ * @see org.apache.wicket.Component#onBeforeRender()
+ */
+ @Override
+ protected void onBeforeRender()
+ {
+ dateField.setRequired(isRequired());
+ hoursField.setRequired(isRequired());
+ minutesField.setRequired(isRequired());
+
+ boolean use12HourFormat = use12HourFormat();
+ amOrPmChoice.setVisible(use12HourFormat);
+
+ 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();
+ }
+
+ /**
+ * Change a date in another timezone
+ *
+ * @param date
+ * The input date.
+ * @param zone
+ * The target timezone.
+ * @return A new converted date.
+ */
+ public static Date changeTimeZone(Date date, TimeZone zone)
+ {
+ Calendar first = Calendar.getInstance(zone);
+ first.setTimeInMillis(date.getTime());
+
+ Calendar output = Calendar.getInstance();
+ output.set(Calendar.YEAR, first.get(Calendar.YEAR));
+ output.set(Calendar.MONTH, first.get(Calendar.MONTH));
+ output.set(Calendar.DAY_OF_MONTH, first.get(Calendar.DAY_OF_MONTH));
+ output.set(Calendar.HOUR_OF_DAY, first.get(Calendar.HOUR_OF_DAY));
+ output.set(Calendar.MINUTE, first.get(Calendar.MINUTE));
+ output.set(Calendar.SECOND, first.get(Calendar.SECOND));
+ output.set(Calendar.MILLISECOND, first.get(Calendar.MILLISECOND));
+
+ return output.getTime();
+ }
+
+ /**
+ * Checks whether the current {@link Locale} uses the 12h or 24h time format. This method can be
+ * overridden to e.g. always use 24h format.
+ *
+ * @return true, if the current {@link Locale} uses the 12h format.<br/>
+ * false, otherwise
+ */
+ protected boolean use12HourFormat()
+ {
+ // TODO Fix !
+ return false;
+// String pattern = DateTimeFormat.patternForStyle("-S", getLocale());
+// return pattern.indexOf('a') != -1 || pattern.indexOf('h') != -1
+// || pattern.indexOf('K') != -1;
+ }
+
+ /**
+ * @return either 12 or 24, depending on the hour format of the current {@link Locale}
+ */
+ private int getMaximumHours()
+ {
+ return getMaximumHours(use12HourFormat());
+ }
+
+ /**
+ * Convenience method (mainly for optimization purposes), in case {@link #use12HourFormat()} has
+ * already been stored in a local variable and thus doesn't need to be computed again.
+ *
+ * @param use12HourFormat
+ * the hour format to use
+ * @return either 12 or 24, depending on the parameter <code>use12HourFormat</code>
+ */
+ private int getMaximumHours(boolean use12HourFormat)
+ {
+ return use12HourFormat ? 12 : 24;
+ }
+//
+// /**
+// * The DatePicker that gets added to the DateTimeField component. Users may override this method
+// * with a DatePicker of their choice.
+// *
+// * @return a new {@link DatePicker} instance
+// */
+// protected DatePicker newDatePicker()
+// {
+// return new DatePicker()
+// {
+// private static final long serialVersionUID = 1L;
+//
+// @Override
+// protected void configure(final Map<String, Object> widgetProperties,
+// final IHeaderResponse response, final Map<String, Object> initVariables)
+// {
+// super.configure(widgetProperties, response, initVariables);
+//
+// DateTimeField.this.configure(widgetProperties);
+// }
+// };
+// }
+
+ protected class HoursModel implements IModel<Integer>
+ {
+ @Override
+ public Integer getObject()
+ {
+ return dateTime.getHour();
+ }
+
+ @Override
+ public void setObject(Integer hour)
+ {
+ dateTime = dateTime.with(ChronoField.HOUR_OF_DAY, hour);
+ }
+
+ @Override
+ public void detach()
+ {
+ }
+ }
+
+ protected class MinutesModel implements IModel<Integer>
+ {
+ @Override
+ public Integer getObject()
+ {
+ return dateTime.getMinute();
+ }
+
+ @Override
+ public void setObject(Integer minute)
+ {
+ dateTime = dateTime.with(ChronoField.MINUTE_OF_HOUR, minute);
+ }
+
+ @Override
+ public void detach()
+ {
+ }
+ }
+
+ protected class AmPmModel implements IModel<AM_PM>
+ {
+ @Override
+ public AM_PM getObject()
+ {
+ int i = dateTime.get(ChronoField.AMPM_OF_DAY);
+ return i == 0 ? AM_PM.AM : AM_PM.PM;
+ }
+
+ @Override
+ public void setObject(AM_PM amPm)
+ {
+ int i = AM_PM.AM == amPm ? 0 : 1;
+ dateTime = dateTime.with(ChronoField.AMPM_OF_DAY, i);
+ }
+
+ @Override
+ public void detach()
+ {
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternDateConverter.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternDateConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternDateConverter.java
index 7efb2d3..14dc4fe 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternDateConverter.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternDateConverter.java
@@ -20,6 +20,8 @@ import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
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
@@ -70,11 +72,7 @@ public class PatternDateConverter extends DateConverter
{
super(applyTimeZoneDifference);
- if (datePattern == null)
- {
- throw new IllegalArgumentException("datePattern must be not null");
- }
- this.datePattern = datePattern;
+ this.datePattern = Args.notNull(datePattern, "datePattern");
}
/**
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/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 9320102..9eef6c5 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
@@ -46,6 +46,8 @@ public class StyleDateConverter extends DateConverter
*/
private final FormatStyle dateStyle;
+ private final FormatStyle timeStyle;
+
/**
* Construct. The dateStyle 'S-' (which is the same as {@link DateTimeFormatter#ofLocalizedDate(FormatStyle)}) will
* be used for constructing the date format for the current locale. </p> When
@@ -61,7 +63,7 @@ public class StyleDateConverter extends DateConverter
*/
public StyleDateConverter(boolean applyTimeZoneDifference)
{
- this(FormatStyle.SHORT, applyTimeZoneDifference);
+ this(FormatStyle.SHORT, FormatStyle.SHORT, applyTimeZoneDifference);
}
/**
@@ -75,19 +77,24 @@ public class StyleDateConverter extends DateConverter
* the client sees 12/24. </p>
*
* @param dateStyle
- * Date style to use. The first character is the date style, and the second character
- * is the time style. Specify a character of 'S' for short style, 'M' for medium, 'L'
- * for long, and 'F' for full. A date or time may be ommitted by specifying a style
- * character '-'. See {@link DateTimeFormatter#ofLocalizedDate(FormatStyle)}.
+ * Date style to use. See {@link DateTimeFormatter#ofLocalizedDate(FormatStyle)}.
+ * @param timeStyle
+ * Time style to use. See {@link DateTimeFormatter#ofLocalizedTime(FormatStyle)}
* @param applyTimeZoneDifference
* whether to apply the difference in time zones between client and server
* @throws IllegalArgumentException
* in case dateStyle is null
*/
- public StyleDateConverter(FormatStyle dateStyle, boolean applyTimeZoneDifference)
+ public StyleDateConverter(FormatStyle dateStyle, FormatStyle timeStyle, boolean applyTimeZoneDifference)
{
super(applyTimeZoneDifference);
this.dateStyle = Args.notNull(dateStyle, "dateStyle");
+ this.timeStyle = Args.notNull(timeStyle, "timeStyle");
+ }
+
+ public StyleDateConverter(String dateTimeStyle, boolean applyTimeZoneDifference)
+ {
+ this(parseFormatStyle(dateTimeStyle.charAt(0)), parseFormatStyle(dateTimeStyle.charAt(1)), applyTimeZoneDifference);
}
/**
@@ -95,10 +102,12 @@ public class StyleDateConverter extends DateConverter
*
* @return datePattern
*/
+ @Deprecated
@Override
public final String getDatePattern(Locale locale)
{
- return DateTimeFormatter.ofLocalizedDate(dateStyle).withLocale(locale).toString();
+ // TODO this doesn't return a pattern!
+ return DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle).withLocale(locale).toString();
}
/**
@@ -107,7 +116,12 @@ public class StyleDateConverter extends DateConverter
@Override
protected DateTimeFormatter getFormat(Locale locale)
{
- return DateTimeFormatter.ofPattern(getDatePattern(locale))
+ return DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle)
.withLocale(locale);
}
+
+ public static FormatStyle parseFormatStyle(char style)
+ {
+ return DateTextField.parseFormatStyle(style);
+ }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/1b997163/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/TimeField.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/TimeField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/TimeField.java
new file mode 100644
index 0000000..aa0dea8
--- /dev/null
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/TimeField.java
@@ -0,0 +1,71 @@
+/*
+ * 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.ZonedDateTime;
+import java.util.Locale;
+
+import org.apache.wicket.model.IModel;
+
+/**
+ * Works on a {@link java.util.Date} object. Displays 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 TimeField}'s {@link Locale}, as does the visibility of the AM/PM field (see
+ * {@link TimeField#use12HourFormat}).
+ *
+ * @author eelcohillenius
+ * @see DateField for a variant with just the date field and date picker
+ */
+public class TimeField extends DateTimeField
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ *
+ * @param id
+ * the component id
+ */
+ public TimeField(String id)
+ {
+ this(id, null);
+ }
+
+ /**
+ * Construct.
+ *
+ * @param id
+ * the component id
+ * @param model
+ * the component's model
+ */
+ public TimeField(String id, IModel<ZonedDateTime> model)
+ {
+ super(id, model);
+
+ getDateTextField().setVisibilityAllowed(false);
+ }
+
+ @Override
+ public void convertInput()
+ {
+ ZonedDateTime modelObject = getModelObject();
+ getDateTextField().setConvertedInput(modelObject != null ? modelObject.toLocalDate() : newDateInstance());
+ super.convertInput();
+ }
+
+}
[2/2] wicket git commit: WICKET-6105 Decommission Wicket-Datetime
module
Posted by mg...@apache.org.
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;
}
/**