WICKET-6200 restructured, fixed javadoc, removed wrong code
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/8567308e Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/8567308e Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/8567308e Branch: refs/heads/WICKET-6105-java.time Commit: 8567308e56d6c4d2c9840daa71775c13fcb0ab81 Parents: 39bbfb9 Author: Sven Meier <[email protected]> Authored: Fri Oct 13 14:46:22 2017 +0200 Committer: Sven Meier <[email protected]> Committed: Sun Oct 15 17:51:43 2017 +0200 ---------------------------------------------------------------------- .../org/apache/wicket/ConverterLocator.java | 3 + .../ajax/builtin/modal/ModalContent1Page.java | 4 +- .../ajax/builtin/modal/ModalPanel1.java | 4 +- .../bean/validation/BeanValidationPage.html | 2 +- .../bean/validation/BeanValidationPage.java | 11 +- .../examples/datetime/DateTimeApplication.java | 12 +- .../wicket/examples/datetime/DateTimePage.html | 53 ++- .../wicket/examples/datetime/DateTimePage.java | 268 +++++++++++-- .../examples/datetime/DateTimePage.properties | 17 + .../wicket/extensions/Initializer.properties | 7 + .../form/datetime/AbstractDateTimeField.html | 3 +- .../form/datetime/AbstractDateTimeField.java | 194 +++++++--- .../markup/html/form/datetime/DateField.java | 252 ------------- .../html/form/datetime/DateTimeField.java | 115 ------ .../html/form/datetime/LocalDateConverter.java | 104 ------ .../html/form/datetime/LocalDateTextField.java | 163 ++++++++ .../html/form/datetime/LocalDateTimeField.java | 74 ++++ .../form/datetime/LocalDateTimeTextField.java | 163 ++++++++ .../html/form/datetime/LocalTimeConverter.java | 104 ------ .../html/form/datetime/LocalTimeTextField.java | 163 ++++++++ .../form/datetime/PatternDateConverter.java | 85 ----- .../form/datetime/PatternTimeConverter.java | 85 ----- .../datetime/PatternZonedDateTimeConverter.java | 97 ----- .../html/form/datetime/StyleDateConverter.java | 118 ------ .../html/form/datetime/StyleTimeConverter.java | 114 ------ .../datetime/StyleZonedDateTimeConverter.java | 168 --------- .../markup/html/form/datetime/TimeField.html | 4 +- .../markup/html/form/datetime/TimeField.java | 373 ++++++------------- .../form/datetime/ZonedDateTimeConverter.java | 203 ---------- .../html/form/datetime/ZonedDateTimeField.java | 94 +---- .../datetime/ZonedToLocalDateTimeModel.java | 118 ++++++ .../html/form/datetime/DateConverterTest.java | 109 ------ .../html/form/datetime/DateTimeFieldTest.java | 14 +- .../datetime/ZonedToLocalDateTimeModelTest.java | 65 ++++ .../converter/ZonedDateTimeConverter.java | 5 +- .../converter/ZonedDateTimeConverterTest.java | 7 +- 36 files changed, 1344 insertions(+), 2031 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java b/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java index 373f3cd..dbef956 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java +++ b/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java @@ -22,6 +22,7 @@ import java.math.BigInteger; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -48,6 +49,7 @@ import org.apache.wicket.util.convert.converter.ShortConverter; import org.apache.wicket.util.convert.converter.SqlDateConverter; import org.apache.wicket.util.convert.converter.SqlTimeConverter; import org.apache.wicket.util.convert.converter.SqlTimestampConverter; +import org.apache.wicket.util.convert.converter.ZonedDateTimeConverter; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.lang.Objects; @@ -184,6 +186,7 @@ public class ConverterLocator implements IConverterLocator set(LocalDate.class, new LocalDateConverter()); set(LocalDateTime.class, new LocalDateTimeConverter()); set(LocalTime.class, new LocalTimeConverter()); + set(ZonedDateTime.class, new ZonedDateTimeConverter()); } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/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 5c252e4..94ba192 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 @@ -20,7 +20,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.markup.html.form.datetime.DateTimeField; +import org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTimeField; import org.apache.wicket.markup.html.WebPage; @@ -65,7 +65,7 @@ public class ModalContent1Page extends WebPage } }); - add(new DateTimeField("dateTimeField")); + add(new LocalDateTimeField("dateTimeField")); final ModalWindow modal; add(modal = new ModalWindow("modal")); http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/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 3a9389a..884077c 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 @@ -16,7 +16,7 @@ */ package org.apache.wicket.examples.ajax.builtin.modal; -import org.apache.wicket.extensions.markup.html.form.datetime.DateTimeField; +import org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTimeField; import org.apache.wicket.markup.html.panel.Panel; /** @@ -32,6 +32,6 @@ public class ModalPanel1 extends Panel public ModalPanel1(String id) { super(id); - add(new DateTimeField("dateTimeField")); + add(new LocalDateTimeField("dateTimeField")); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html b/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html index db04a1c..7b5f6fa 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html @@ -34,7 +34,7 @@ <tr> <td><label wicket:for="birthdate"><wicket:label>Birthdate</wicket:label></label></td> <td><input wicket:id="birthdate" type="text" size="10"/></td> - <td><pre class="note">m/d/yyyy field with @Past</pre></td> + <td><pre class="note"><span wicket:id="pattern" /> field with @Past</pre></td> </tr> <tr> <td><label wicket:for="password"><wicket:label>Password</wicket:label></label></td> http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java index e1eb59d..3173867 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java @@ -16,12 +16,14 @@ */ package org.apache.wicket.examples.bean.validation; +import java.time.format.FormatStyle; + import org.apache.wicket.bean.validation.PropertyValidator; -import org.apache.wicket.extensions.markup.html.form.datetime.DateField; -import org.apache.wicket.extensions.markup.html.form.datetime.StyleDateConverter; import org.apache.wicket.examples.WicketExamplePage; +import org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTextField; import org.apache.wicket.feedback.ExactLevelFeedbackMessageFilter; import org.apache.wicket.feedback.FeedbackMessage; +import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.FeedbackPanel; @@ -52,8 +54,9 @@ public class BeanValidationPage extends WicketExamplePage form.add(new TextField<>("name", new PropertyModel<String>(this, "person.name")).add(new PropertyValidator<>())); form.add(new TextField<>("phone", new PropertyModel<String>(this, "person.phone")).add(new PropertyValidator<>())); form.add(new TextField<>("email", new PropertyModel<String>(this, "person.email")).add(new PropertyValidator<>())); - form.add(new DateField("birthdate", new PropertyModel<>(this, "person.birthdate"), - new StyleDateConverter("S-")).add(new PropertyValidator<>())); + LocalDateTextField dateField = new LocalDateTextField("birthdate", new PropertyModel<>(this, "person.birthdate"), FormatStyle.SHORT); + form.add(dateField.add(new PropertyValidator<>())); + form.add(new Label("pattern", new PropertyModel<>(dateField, "textFormat"))); form.add(new TextField<>("password", new PropertyModel<String>(this, "person.password")).add(new PropertyValidator<>())); add(new FeedbackPanel("feedbackSuccess", new ExactLevelFeedbackMessageFilter(FeedbackMessage.INFO))); http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java index 7dc4282..713f5b7 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java @@ -26,8 +26,16 @@ import org.apache.wicket.examples.WicketExampleApplication; public class DateTimeApplication extends WicketExampleApplication { @Override + protected void init() + { + super.init(); + + getRequestCycleSettings().setGatherExtendedBrowserInfo(true); + } + + @Override public Class< ? extends Page> getHomePage() { return DateTimePage.class; - } -} + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html index eed5878..2589935 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html @@ -9,26 +9,51 @@ <body> <span wicket:id="mainNavigation" /> - <h3>Demo for short style time</h3> - <span wicket:id="time1"></span><br/> - - <hr/> + <form wicket:id="form"> + <div> + <wicket:message key="locale"></wicket:message> + <select wicket:id="localeSelect"></select> + <a href="#" wicket:id="defaultLocaleLink">[<wicket:message key="default" />]</a> + </div> + + <hr/> + + <h3>TimeField 12-hours</h3> + <span wicket:id="time1"></span><br/> + + <hr/> + + <h3>TimeField 24-hours</h3> + <span wicket:id="time2"></span><br/> + + <hr/> - <h3>Demo for Full style time</h3> - <span wicket:id="time2"></span><br/> + <h3>LocalDateTimeField (default time 00:00)</h3> + <span wicket:id="datetime0"></span><br/> - <hr/> + <hr/> - <h3>Demo for Short style time with 24-hours</h3> - <span wicket:id="time3"></span><br/> + <wicket:message key="clientZone"></wicket:message> + <select wicket:id="zoneSelect"></select> + <br/> + + <h3>LocalDateTimeField with a ZonedDateTime (<span wicket:id="datetime1-label" />) adjusted to client's time zone</h3> + <span wicket:id="datetime1"></span> + <br/> - <hr/> + <h3>LocalDateTimeTextField with a ZonedDateTime (<span wicket:id="datetime2-label" />) adjusted to client's time zone</h3> + <input wicket:id="datetime2" type="text" /> + <br/> + + <h3>ZonedDateTimeField</h3> + <span wicket:id="datetime3"></span> + <br/> + + <hr/> - <form wicket:id="form"> - <h3>Demo for default Local Date Time in Form</h3> - <span wicket:id="datetime1"></span><br/> - <input wicket:id="submit" type="submit" value="Submit"/> <div wicket:id="feedback"></div> + + <input wicket:id="submit" type="submit" value="Submit"/> </form> </body> </html> http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java index 6294863..b102c2e 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java @@ -18,16 +18,36 @@ package org.apache.wicket.examples.datetime; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.FormatStyle; +import java.time.format.TextStyle; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.Session; import org.apache.wicket.examples.WicketExamplePage; -import org.apache.wicket.extensions.markup.html.form.datetime.DateTimeField; -import org.apache.wicket.extensions.markup.html.form.datetime.StyleTimeConverter; +import org.apache.wicket.examples.forminput.FormInputApplication; +import org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTimeField; +import org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTimeTextField; import org.apache.wicket.extensions.markup.html.form.datetime.TimeField; +import org.apache.wicket.extensions.markup.html.form.datetime.ZonedDateTimeField; +import org.apache.wicket.extensions.markup.html.form.datetime.ZonedToLocalDateTimeModel; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Button; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.FormComponentUpdatingBehavior; +import org.apache.wicket.markup.html.form.IChoiceRenderer; +import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.panel.FeedbackPanel; -import org.apache.wicket.model.Model; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.protocol.http.request.WebClientInfo; +import org.apache.wicket.request.http.WebRequest; /** * DateTime example page. @@ -37,43 +57,231 @@ public class DateTimePage extends WicketExamplePage { private static final long serialVersionUID = 1L; + private ZoneId clientZone; + + private ZoneId targetZone = ZoneId.of("UTC+8"); + + @SuppressWarnings("unused") + private LocalTime time1 = LocalTime.of(22, 15); + + @SuppressWarnings("unused") + private LocalTime time2 = LocalTime.of(22, 15); + + @SuppressWarnings("unused") + private LocalDateTime dateTime0 = LocalDateTime.now(); + + @SuppressWarnings("unused") + private ZonedDateTime dateTime1 = LocalDateTime.now().atZone(targetZone); + + @SuppressWarnings("unused") + private ZonedDateTime dateTime2 = LocalDateTime.now().atZone(targetZone); + + @SuppressWarnings("unused") + private ZonedDateTime dateTime3 = ZonedDateTime.now(); + /** * Constructor. */ public DateTimePage() { - add(TimeField.forShortStyle("time1", Model.of(LocalTime.of(22, 15)))); - add(TimeField.forTimeStyle("time2", Model.of(LocalTime.of(22, 15)), "F")); - add(new TimeField("time3", Model.of(LocalTime.of(22, 15)), new StyleTimeConverter("S")) { + Form<String> form = new Form<>("form"); + this.add(form); + + form.add(new ZoneDropDownChoice("zoneSelect")); + + // Dropdown for selecting locale + form.add(new LocaleDropDownChoice("localeSelect")); + + // Link to return to default locale + form.add(new Link<Void>("defaultLocaleLink") + { + public void onClick() + { + WebRequest request = (WebRequest)getRequest(); + getSession().setLocale(request.getLocale()); + } + }); + + form.add(new TimeField("time1", new PropertyModel<>(this, "time1")) + { + private static final long serialVersionUID = 1L; + + @Override + protected boolean use12HourFormat() + { + return true; + } + }); + + form.add(new TimeField("time2", new PropertyModel<>(this, "time2")) + { private static final long serialVersionUID = 1L; @Override - protected boolean use12HourFormat() { + protected boolean use12HourFormat() + { return false; } }); - final DateTimeField datetime1 = new DateTimeField("datetime1", Model.of(LocalDateTime.now())); + + final LocalDateTimeField datetimeField0 = new LocalDateTimeField("datetime0", + new PropertyModel<>(this, "dateTime0")) + { + @Override + protected LocalTime getDefaultTime() + { + return LocalTime.of(0, 0); + } + }; + form.add(datetimeField0); + + IModel<ZonedDateTime> zonedDateTime1 = new PropertyModel<>(this, "dateTime1"); + final LocalDateTimeField datetimeField1 = new LocalDateTimeField("datetime1", + new ZonedToLocalDateTimeModel(zonedDateTime1) + { + @Override + protected ZoneId getClientTimeZone() + { + return clientZone; + } + + @Override + protected ZoneId getTargetTimeZone() + { + return targetZone; + } + }); + form.add(datetimeField1); + form.add(new Label("datetime1-label", zonedDateTime1)); + + IModel<ZonedDateTime> zonedDateTime2 = new PropertyModel<>(this, "dateTime2"); + LocalDateTimeTextField datetime2 = new LocalDateTimeTextField("datetime2", + new ZonedToLocalDateTimeModel(zonedDateTime2) + { + @Override + protected ZoneId getClientTimeZone() + { + return clientZone; + } + + @Override + protected ZoneId getTargetTimeZone() + { + return targetZone; + } + }, FormatStyle.SHORT, FormatStyle.SHORT); + form.add(datetime2); + form.add(new Label("datetime2-label", zonedDateTime2)); + + final ZonedDateTimeField datetimeField3 = new ZonedDateTimeField("datetime3", + new PropertyModel<>(this, "dateTime3")); + form.add(datetimeField3); + final FeedbackPanel feedback = new FeedbackPanel("feedback"); - Form<String> form = new Form<>("form"); - add(form.add(datetime1) - .add(feedback.setOutputMarkupId(true)) - .add(new AjaxButton("submit") + form.add(feedback); + + form.add(new Button("submit")); + } + + @Override + protected void onInitialize() + { + super.onInitialize(); + + clientZone = ((WebClientInfo)Session.get().getClientInfo()).getProperties().getTimeZone() + .toZoneId(); + } + + /** + * Choice for a locale. + */ + private final class LocaleChoiceRenderer extends ChoiceRenderer<Locale> + { + @Override + public Object getDisplayValue(Locale locale) + { + return locale.getDisplayName(getLocale()); + } + } + + /** + * Dropdown with Locales. + */ + private final class LocaleDropDownChoice extends DropDownChoice<Locale> + { + /** + * Construct. + * + * @param id + * component id + */ + public LocaleDropDownChoice(String id) + { + super(id, FormInputApplication.LOCALES, new LocaleChoiceRenderer()); + + setModel(new PropertyModel<>(this, "session.locale")); + + add(new FormComponentUpdatingBehavior() + { + @Override + protected void onUpdate() + { + setResponsePage(getPage().getClass()); + } + }); + } + } + + private class ZoneDropDownChoice extends DropDownChoice<ZoneId> + { + + public ZoneDropDownChoice(String id) + { + super(id, new IModel<List<ZoneId>>() + { + @Override + public List<ZoneId> getObject() + { + return ZoneId.getAvailableZoneIds().stream().map(id -> ZoneId.of(id)) + .collect(Collectors.toList()); + } + }); + + setModel(new PropertyModel<ZoneId>(DateTimePage.this, "clientZone")); + + setChoiceRenderer(new IChoiceRenderer<ZoneId>() + { + @Override + public Object getDisplayValue(ZoneId object) + { + String name = object.getDisplayName(TextStyle.FULL, getLocale()); + + ZoneOffset offset = LocalDateTime.now().atZone(object).getOffset(); + + return name + offset; + } + + @Override + public String getIdValue(ZoneId object, int index) + { + return object.getId(); + } + + @Override + public ZoneId getObject(String id, IModel<? extends List<? extends ZoneId>> choices) + { + return ZoneId.of(id); + } + }); + + add(new FormComponentUpdatingBehavior() + { + protected void onUpdate() { - private static final long serialVersionUID = 1L; - - @Override - protected void onSubmit(AjaxRequestTarget target) - { - form.info(String.format("DateTime was just submitted: %s", datetime1.getModelObject())); - target.add(feedback); - } - - @Override - protected void onError(AjaxRequestTarget target) - { - target.add(feedback); - } - }) - ); + // clear raw input of all inputs so that values are reformatted + getForm().clearInput(); + }; + }); + } } } http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties new file mode 100644 index 0000000..6a4447b --- /dev/null +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties @@ -0,0 +1,17 @@ +# 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. +locale=Locale +default=default +clientZone=Client timezone http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/Initializer.properties ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/Initializer.properties b/wicket-extensions/src/main/java/org/apache/wicket/extensions/Initializer.properties index 326f2a7..b9a7819 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/Initializer.properties +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/Initializer.properties @@ -38,3 +38,10 @@ Folder.CSS.other=tree-folder-other Folder.CSS.closed=tree-folder-closed Folder.CSS.open=tree-folder-open Folder.CSS.selected=selected + +AbstractDateTimeField.timeSeparator=\u00a0-\u00a0 +AbstractDateTimeField.CSS.date=datetime-date +AbstractDateTimeField.CSS.time=datetime-time +TimeField.hoursSeparator=\u00a0:\u00a0 +TimeField.CSS.hours=time-hours +TimeField.CSS.minutes=time-minutes \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.html ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.html b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.html index d92f2ce..3230a08 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.html +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.html @@ -16,8 +16,9 @@ limitations under the License. --> <wicket:panel xmlns:wicket="http://wicket.apache.org"> - <span style="white-space: nowrap;"> + <span> <input type="text" wicket:id="date" size="12" /> + <span wicket:id="timeSeparator"> - </span> <span wicket:id="time" /> </span> </wicket:panel> http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.java index 8b6f85d..2f86c19 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/AbstractDateTimeField.java @@ -18,24 +18,25 @@ package org.apache.wicket.extensions.markup.html.form.datetime; import java.time.LocalDate; import java.time.LocalTime; +import java.time.format.FormatStyle; import java.time.temporal.Temporal; import java.util.Date; -import java.util.Locale; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.core.util.string.CssUtils; +import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.FormComponentPanel; import org.apache.wicket.model.IModel; +import org.apache.wicket.model.ResourceModel; +import org.apache.wicket.util.convert.ConversionException; /** - * Works on a {@link java.time.ZonedDateTime} object. Displays a date field and a DatePicker, a field - * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field - * depends on the time format of this {@link AbstractDateTimeField}'s {@link Locale}, as does the visibility - * of the AM/PM field (see {@link AbstractDateTimeField#use12HourFormat}). + * Works on a {@link java.time.Temporal} object, aggregating a {@link LocalDateTextField} and a {@link TimeField}. * <p> - * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an - * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained - * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling - * {@link #processInput()}: + * <strong>Ajaxifying an AbstractDateTimeField</strong>: + * If you want to update this component with an {@link AjaxFormComponentUpdatingBehavior}, you have to attach it + * to the contained components by overriding {@link #newDateTextField(String, IModel)}: * * <pre>{@code * DateTimeField dateTimeField = new DateTimeField(...) { @@ -55,19 +56,17 @@ import org.apache.wicket.model.IModel; * }</pre> * * @author eelcohillenius - * @see DateField for a variant with just the date field and date picker */ abstract class AbstractDateTimeField<T extends Temporal> extends FormComponentPanel<T> { private static final long serialVersionUID = 1L; - // Component-IDs - protected static final String DATE = "date"; - protected static final String TIME = "time"; + public static final String DATE_CSS_CLASS_KEY = CssUtils.key(AbstractDateTimeField.class, "date"); - // The date TextField and it's associated model object - // Note that any time information in date will be ignored - private DateField dateField; + public static final String TIME_CSS_CLASS_KEY = CssUtils.key(AbstractDateTimeField.class, "time"); + + private LocalDateTextField localDateField; + private TimeField timeField; /** @@ -90,18 +89,38 @@ abstract class AbstractDateTimeField<T extends Temporal> extends FormComponentPa { super(id, model); - // Create and add the date TextField - add(dateField = newDateField(DATE, new DateModel())); - add(timeField = newTimeField(TIME, new TimeModel())); + add(new Label("timeSeparator", new ResourceModel("AbstractDateTimeField.timeSeparator")) + { + private static final long serialVersionUID = 1L; + + @Override + protected void onConfigure() + { + super.onConfigure(); + + timeField.configure(); + + setVisible(timeField.isVisible()); + } + }); + } + + @Override + protected void onInitialize() + { + super.onInitialize(); + + add(localDateField = newDateField("date", new DateModel())); + add(timeField = newTimeField("time", new TimeModel())); } /** * * @return The date TextField */ - protected final DateField getDateField() + protected final LocalDateTextField getDateField() { - return dateField; + return localDateField; } /** @@ -118,7 +137,7 @@ abstract class AbstractDateTimeField<T extends Temporal> extends FormComponentPa { // since we override convertInput, we can let this method return a value // that is just suitable for error reporting - return String.format("%s, %s", dateField.getInput(), timeField.getInput()); + return String.format("%s, %s", localDateField.getInput(), timeField.getInput()); } /** @@ -134,47 +153,68 @@ abstract class AbstractDateTimeField<T extends Temporal> extends FormComponentPa @Override public void convertInput() { - try - { - // Get the converted input values - LocalDate date = dateField.getConvertedInput(); - LocalTime time = timeField.getConvertedInput(); + // Get the converted input values + LocalDate date = localDateField.getConvertedInput(); + LocalTime time = timeField.getConvertedInput(); - if (date == null || time == null) + T temporal; + if (date == null && time == null) + { + temporal = null; + } + else + { + if (date == null) { - setConvertedInput(null); + error(newValidationError(new ConversionException("Cannot create temporal without date").setTargetType(getType()))); + return; } - else + if (time == null) { - // Use the input to create proper date-time - setConvertedInput(performConvert(date, time)); + time = getDefaultTime(); + if (time == null) { + error(newValidationError(new ConversionException("Cannot create temporal without time").setTargetType(getType()))); + return; + } } + + // Use the input to create proper date-time + temporal = createTemporal(date, time); } - catch (RuntimeException e) - { - AbstractDateTimeField.this.error(e.getMessage()); - invalid(); - } + + setConvertedInput(temporal); } - abstract T performConvert(LocalDate date, LocalTime time); - - void prepareObject() { - // no-op by default + /** + * Get a default time if none was entered. + * + * @return {@value null} by default + */ + protected LocalTime getDefaultTime() + { + return null; } /** - * create a new {@link DateField} instance to be added to this panel. + * create a new {@link LocalDateTextField} instance to be added to this panel. * * @param id * the component id * @param dateFieldModel - * model that should be used by the {@link DateField} + * model that should be used by the {@link LocalDateTextField} * @return a new date text field instance */ - protected DateField newDateField(String id, IModel<LocalDate> dateFieldModel) + protected LocalDateTextField newDateField(String id, IModel<LocalDate> dateFieldModel) { - return DateField.forShortStyle(id, dateFieldModel); + return new LocalDateTextField(id, dateFieldModel, FormatStyle.SHORT) { + @Override + protected void onComponentTag(ComponentTag tag) + { + super.onComponentTag(tag); + + tag.append("class", getString(DATE_CSS_CLASS_KEY), " "); + } + }; } /** @@ -188,7 +228,15 @@ abstract class AbstractDateTimeField<T extends Temporal> extends FormComponentPa */ protected TimeField newTimeField(String id, IModel<LocalTime> timeFieldModel) { - return TimeField.forShortStyle(id, timeFieldModel); + return new TimeField(id, timeFieldModel) { + @Override + protected void onComponentTag(ComponentTag tag) + { + super.onComponentTag(tag); + + tag.append("class", getString(TIME_CSS_CLASS_KEY), " "); + } + }; } /** @@ -197,50 +245,78 @@ abstract class AbstractDateTimeField<T extends Temporal> extends FormComponentPa @Override protected void onBeforeRender() { - dateField.setRequired(isRequired()); + localDateField.setRequired(isRequired()); timeField.setRequired(isRequired()); - prepareObject(); - super.onBeforeRender(); } - abstract LocalDate getLocalDate(); - abstract void setLocalDate(LocalDate date); - abstract LocalTime getLocalTime(); - abstract void setLocalTime(LocalTime time); + /** + * Get the local date from the given temporal. + * + * @param temporal + * @return local date + */ + protected abstract LocalDate getLocalDate(T temporal); - protected class DateModel implements IModel<LocalDate> + /** + * Get the time from the given temporal. + * + * @param temporal + * @return time + */ + protected abstract LocalTime getLocalTime(T temporal); + + /** + * Create the temporal object from date and time. + * + * @param date + * @param time + * @return + */ + protected abstract T createTemporal(LocalDate date, LocalTime time); + + private class DateModel implements IModel<LocalDate> { private static final long serialVersionUID = 1L; @Override public LocalDate getObject() { - return getLocalDate(); + T temporal = getModelObject(); + if (temporal == null) { + return null; + } + + return getLocalDate(temporal); } @Override public void setObject(LocalDate date) { - setLocalDate(date); + // ignored } } - protected class TimeModel implements IModel<LocalTime> + private class TimeModel implements IModel<LocalTime> { private static final long serialVersionUID = 1L; @Override public LocalTime getObject() { - return getLocalTime(); + T temporal = getModelObject(); + if (temporal == null) { + return null; + } + + return getLocalTime(temporal); } @Override public void setObject(LocalTime time) { - setLocalTime(time); + // ignored } } } http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/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 deleted file mode 100644 index 895c0c6..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateField.java +++ /dev/null @@ -1,252 +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.markup.html.form.datetime; - -import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.time.format.FormatStyle; - -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.time.LocalDate</code> object and that uses java.time 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 ZonedDateTimeConverter#getApplyTimeZoneDifference() date converter} of this package for more - * information on that. - * </p> - * - * @see StyleZonedDateTimeConverter - * @see java.time.ZonedDateTime - * @see java.time.format.DateTimeFormatter - * @see java.time.ZoneId - * - * @author eelcohillenius - */ -public class DateField extends TextField<LocalDate> implements ITextFormatProvider -{ - private static final long serialVersionUID = 1L; - - /** - * Creates a new DateField 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 DateField - */ - public static DateField forDatePattern(String id, IModel<LocalDate> model, String datePattern) - { - return new DateField(id, model, new PatternDateConverter(datePattern)); - } - - /** - * Creates a new DateField 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 DateField - */ - public static DateField forDatePattern(String id, String datePattern) - { - return forDatePattern(id, null, datePattern); - } - - /** - * Creates a new DateField 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 DateField - */ - public static DateField forDateStyle(String id, IModel<LocalDate> model, String dateStyle) - { - return new DateField(id, model, new StyleDateConverter(dateStyle)); - } - - /** - * Creates a new DateField 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 DateField - */ - public static DateField forDateStyle(String id, String dateStyle) - { - return forDateStyle(id, null, dateStyle); - } - - /** - * Creates a new DateField defaulting to using a short date pattern - * - * @param id - * The id of the text field - * @return DateField - */ - public static DateField forShortStyle(String id) - { - return forShortStyle(id, null); - } - - /** - * Creates a new DateField defaulting to using a short date pattern - * - * @param id - * The id of the text field - * @param model - * The model - * @return DateField - */ - public static DateField forShortStyle(String id, IModel<LocalDate> model) - { - return new DateField(id, model, new StyleDateConverter()); - } - - /** - * Creates a new DateField using the provided converter. - * - * @param id - * The id of the text field - * @param converter - * the date converter - * @return DateField - */ - public static DateField withConverter(String id, LocalDateConverter converter) - { - return withConverter(id, null, converter); - } - - /** - * Creates a new DateField using the provided converter. - * - * @param id - * The id of the text field - * @param model - * The model - * @param converter - * the date converter - * @return DateField - */ - public static DateField withConverter(String id, IModel<LocalDate> model, LocalDateConverter converter) - { - return new DateField(id, model, converter); - } - - /** - * The converter for the TextField - */ - private final LocalDateConverter converter; - - /** - * Construct with a converter. - * - * @param id - * The component id - * @param model - * The model - * @param converter - * The converter to use - */ - public DateField(String id, IModel<LocalDate> model, LocalDateConverter 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 DateField(String id, LocalDateConverter converter) - { - this(id, null, converter); - } - - /** - * @return The specialized converter. - * @see org.apache.wicket.Component#createConverter(java.lang.Class) - */ - @Override - protected IConverter<?> createConverter(Class<?> clazz) - { - if (LocalDate.class.isAssignableFrom(clazz)) - { - return converter; - } - return null; - } - - /** - * @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat() - */ - @Override - public final String getTextFormat() - { - return converter.getPattern(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/8567308e/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 deleted file mode 100644 index bc4801c..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/DateTimeField.java +++ /dev/null @@ -1,115 +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.markup.html.form.datetime; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.temporal.ChronoField; -import java.util.Locale; - -import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; -import org.apache.wicket.model.IModel; - -/** - * Works on a {@link java.time.LocalDateTimeTime} object. Displays a date field and a DatePicker, a field - * for hours and a field for minutes, and an AM/PM field. The format (12h/24h) of the hours field - * depends on the time format of this {@link DateTimeField}'s {@link Locale}, as does the visibility - * of the AM/PM field (see {@link DateTimeField#use12HourFormat}). - * <p> - * <strong>Ajaxifying the DateTimeField</strong>: If you want to update a DateTimeField with an - * {@link AjaxFormComponentUpdatingBehavior}, you have to attach it to the contained - * {@link DateField} by overriding {@link #newDateTextField(String, IModel)} and calling - * {@link #processInput()}: - * - * <pre>{@code - * DateTimeField dateTimeField = new DateTimeField(...) { - * protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel) - * { - * DateTextField dateField = super.newDateTextField(id, dateFieldModel); - * dateField.add(new AjaxFormComponentUpdatingBehavior("change") { - * protected void onUpdate(AjaxRequestTarget target) { - * processInput(); // let DateTimeField process input too - * - * ... - * } - * }); - * return recorder; - * } - * } - * }</pre> - * - * @author eelcohillenius - * @see DateField for a variant with just the date field and date picker - */ -public class DateTimeField extends AbstractDateTimeField<LocalDateTime> -{ - private static final long serialVersionUID = 1L; - - private LocalDateTime dateTime = LocalDateTime.now(); - - /** - * Construct. - * - * @param id - */ - public DateTimeField(final String id) - { - this(id, null); - } - - /** - * Construct. - * - * @param id - * @param model - */ - public DateTimeField(final String id, final IModel<LocalDateTime> model) - { - super(id, model); - - // Sets the type that will be used when updating the model for this component. - setType(LocalDateTime.class); - } - - LocalDateTime performConvert(LocalDate date, LocalTime time) { - return LocalDateTime.of(date, time); - } - - LocalDate getLocalDate() - { - return getModelObject() == null ? null : dateTime.toLocalDate(); - } - - void setLocalDate(LocalDate date) - { - dateTime = dateTime.with(ChronoField.YEAR, date.getYear()) - .with(ChronoField.MONTH_OF_YEAR, date.getMonthValue()) - .with(ChronoField.DAY_OF_YEAR, date.getDayOfMonth()); - } - - LocalTime getLocalTime() - { - return getModelObject() == null ? null : dateTime.toLocalTime(); - } - - void setLocalTime(LocalTime time) - { - dateTime = dateTime.with(ChronoField.HOUR_OF_DAY, time.getHour()) - .with(ChronoField.MINUTE_OF_HOUR, time.getMinute()); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateConverter.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateConverter.java deleted file mode 100644 index 95e1a47..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateConverter.java +++ /dev/null @@ -1,104 +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.markup.html.form.datetime; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -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; - - -/** - * Base class for java.time based date converters. It contains the logic to parse and format, - * optionally taking the time zone difference between clients and the server into account. - * <p> - * Converters of this class are best suited for per-component use. - * </p> - * - * @author eelcohillenius - */ -public abstract class LocalDateConverter implements IConverter<LocalDate> -{ - private static final long serialVersionUID = 1L; - - public LocalDate convertToObject(String value, DateTimeFormatter format, Locale locale) { - try - { - // parse date retaining the time of the submission - return LocalDate.parse(value, format); - } - catch (RuntimeException e) - { - throw newConversionException(e, locale); - } - } - - @Override - public LocalDate convertToObject(String value, Locale locale) - { - if (Strings.isEmpty(value)) - { - return null; - } - - DateTimeFormatter format = getFormat(locale); - Args.notNull(format, "format"); - - return convertToObject(value, format, locale); - } - - /** - * Creates a ConversionException and sets additional context information to it. - * - * @param cause - * - {@link RuntimeException} cause - * @param locale - * - {@link Locale} used to set 'format' variable with localized pattern - * @return {@link ConversionException} - */ - ConversionException newConversionException(RuntimeException cause, Locale locale) - { - return new ConversionException(cause) - .setVariable("format", getPattern(locale)); - } - - @Override - public String convertToString(LocalDate dateTime, Locale locale) - { - DateTimeFormatter format = getFormat(locale); - return format.format(dateTime); - } - - /** - * @param locale - * The locale used to convert the value - * @return Gets the pattern that is used for printing and parsing - */ - public abstract String getPattern(Locale locale); - - /** - * @param locale - * The locale used to convert the value - * - * @return formatter The formatter for the current conversion - */ - public abstract DateTimeFormatter getFormat(Locale locale); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTextField.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTextField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTextField.java new file mode 100644 index 0000000..a1d1dc0 --- /dev/null +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTextField.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.extensions.markup.html.form.datetime; + +import java.time.LocalDate; +import java.time.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.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.convert.converter.LocalDateConverter; + +/** + * A TextField that is mapped to a <code>java.time.LocalDate</code> object and that uses java.time time to + * parse and format values. + * + * @see java.time.format.DateTimeFormatter + * + * @author eelcohillenius + */ +public class LocalDateTextField extends TextField<LocalDate> implements ITextFormatProvider +{ + private static final long serialVersionUID = 1L; + + /** + * The converter for the TextField + */ + private final TextFormatConverter converter; + + /** + * Construct with a pattern. + * + * @param id + * the component id + * @param model + * the model + * @param pattern + * the pattern to use + */ + public LocalDateTextField(String id, IModel<LocalDate> model, String datePattern) + { + super(id, model, LocalDate.class); + + this.converter = new TextFormatConverter() { + + @Override + public DateTimeFormatter getDateTimeFormatter(Locale locale) + { + return DateTimeFormatter.ofPattern(datePattern).withLocale(locale); + } + + @Override + public String getTextFormat(Locale locale) + { + return datePattern; + } + }; + } + + /** + * Construct with a pattern. + * + * @param id + * the component id + * @param pattern + * the pattern to use + */ + public LocalDateTextField(String id, String datePattern) + { + this(id, null, datePattern); + } + + /** + * Construct with a style. + * + * @param id + * the component id + * @param model + * the model + * @param dateStyle + * the style to use + */ + public LocalDateTextField(String id, IModel<LocalDate> model, FormatStyle dateStyle) + { + super(id, model, LocalDate.class); + + this.converter = new TextFormatConverter() { + + @Override + public DateTimeFormatter getDateTimeFormatter(Locale locale) + { + return DateTimeFormatter.ofLocalizedDate(dateStyle).withLocale(locale); + } + + @Override + public String getTextFormat(Locale locale) + { + return DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, null, IsoChronology.INSTANCE, locale); + } + }; + } + + + /** + * Construct with a style. + * + * @param id + * the component id + * @param dateStyle + * the style to use + */ + public LocalDateTextField(String id, FormatStyle dateStyle) + { + this(id, null, dateStyle); + } + + /** + * @return The specialized converter. + * @see org.apache.wicket.Component#createConverter(java.lang.Class) + */ + @Override + protected IConverter<?> createConverter(Class<?> clazz) + { + if (LocalDate.class.isAssignableFrom(clazz)) + { + return converter; + } + return null; + } + + /** + * @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat() + */ + @Override + public final String getTextFormat() + { + return converter.getTextFormat(getLocale()); + } + + private abstract class TextFormatConverter extends LocalDateConverter { + + public abstract String getTextFormat(Locale locale); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeField.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeField.java new file mode 100644 index 0000000..2283904 --- /dev/null +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeField.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.extensions.markup.html.form.datetime; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; + +import org.apache.wicket.model.IModel; + +/** + * Works on a {@link java.time.LocalDateTime} object. See {@link AbstractDateTimeField} for + * further details. + * + * @author eelcohillenius + */ +public class LocalDateTimeField extends AbstractDateTimeField<LocalDateTime> +{ + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param id + */ + public LocalDateTimeField(final String id) + { + this(id, null); + } + + /** + * Construct. + * + * @param id + * @param model + */ + public LocalDateTimeField(final String id, final IModel<LocalDateTime> model) + { + super(id, model); + + // Sets the type that will be used when updating the model for this component. + setType(LocalDateTime.class); + } + + @Override + protected LocalDateTime createTemporal(LocalDate date, LocalTime time) { + return LocalDateTime.of(date, time); + } + + @Override + protected LocalDate getLocalDate(LocalDateTime temporal) + { + return temporal.toLocalDate(); + } + + protected LocalTime getLocalTime(LocalDateTime temporal) + { + return temporal.toLocalTime(); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeTextField.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeTextField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeTextField.java new file mode 100644 index 0000000..772b5f3 --- /dev/null +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalDateTimeTextField.java @@ -0,0 +1,163 @@ +/* + * 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.LocalDateTime; +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.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.convert.converter.LocalDateTimeConverter; + +/** + * A TextField that is mapped to a <code>java.time.LocalDateTime</code> object and that uses java.time time to + * parse and format values. + * + * @see java.time.format.DateTimeFormatter + * + * @author eelcohillenius + */ +public class LocalDateTimeTextField extends TextField<LocalDateTime> implements ITextFormatProvider +{ + private static final long serialVersionUID = 1L; + + /** + * The converter for the TextField + */ + private final TextFormatConverter converter; + + /** + * Construct with a pattern. + * + * @param id + * the component id + * @param model + * the model + * @param pattern + * the pattern to use + */ + public LocalDateTimeTextField(String id, IModel<LocalDateTime> model, String dateTimePattern) + { + super(id, model, LocalDateTime.class); + + this.converter = new TextFormatConverter() { + + @Override + public DateTimeFormatter getDateTimeFormatter(Locale locale) + { + return DateTimeFormatter.ofPattern(dateTimePattern).withLocale(locale); + } + + @Override + public String getTextFormat(Locale locale) + { + return dateTimePattern; + } + }; + } + + /** + * Construct with a pattern. + * + * @param id + * the component id + * @param pattern + * the pattern to use + */ + public LocalDateTimeTextField(String id, String dateTimePattern) + { + this(id, null, dateTimePattern); + } + + /** + * Construct with a style. + * + * @param id + * the component id + * @param model + * the model + * @param timeStyle + * the style to use + */ + public LocalDateTimeTextField(String id, IModel<LocalDateTime> model, FormatStyle dateStyle, FormatStyle timeStyle) + { + super(id, model, LocalDateTime.class); + + this.converter = new TextFormatConverter() { + + @Override + public DateTimeFormatter getDateTimeFormatter(Locale locale) + { + return DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle).withLocale(locale); + } + + @Override + public String getTextFormat(Locale locale) + { + return DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, IsoChronology.INSTANCE, locale); + } + }; + } + + + /** + * Construct with a style. + * + * @param id + * the component id + * @param timeStyle + * the style to use + */ + public LocalDateTimeTextField(String id, FormatStyle dateStyle, FormatStyle timeStyle) + { + this(id, null, dateStyle, timeStyle); + } + + /** + * @return The specialized converter. + * @see org.apache.wicket.Component#createConverter(java.lang.Class) + */ + @Override + protected IConverter<?> createConverter(Class<?> clazz) + { + if (LocalDateTime.class.isAssignableFrom(clazz)) + { + return converter; + } + return null; + } + + /** + * @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat() + */ + @Override + public final String getTextFormat() + { + return converter.getTextFormat(getLocale()); + } + + private abstract class TextFormatConverter extends LocalDateTimeConverter { + + public abstract String getTextFormat(Locale locale); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeConverter.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeConverter.java deleted file mode 100644 index 1597ab6..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeConverter.java +++ /dev/null @@ -1,104 +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.markup.html.form.datetime; - -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -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; - - -/** - * Base class for java.time based date converters. It contains the logic to parse and format, - * optionally taking the time zone difference between clients and the server into account. - * <p> - * Converters of this class are best suited for per-component use. - * </p> - * - * @author eelcohillenius - */ -public abstract class LocalTimeConverter implements IConverter<LocalTime> -{ - private static final long serialVersionUID = 1L; - - public LocalTime convertToObject(String value, DateTimeFormatter format, Locale locale) { - try - { - // parse date retaining the time of the submission - return LocalTime.parse(value, format); - } - catch (RuntimeException e) - { - throw newConversionException(e, locale); - } - } - - @Override - public LocalTime convertToObject(String value, Locale locale) - { - if (Strings.isEmpty(value)) - { - return null; - } - - DateTimeFormatter format = getFormat(locale); - Args.notNull(format, "format"); - - return convertToObject(value, format, locale); - } - - /** - * Creates a ConversionException and sets additional context information to it. - * - * @param cause - * - {@link RuntimeException} cause - * @param locale - * - {@link Locale} used to set 'format' variable with localized pattern - * @return {@link ConversionException} - */ - ConversionException newConversionException(RuntimeException cause, Locale locale) - { - return new ConversionException(cause) - .setVariable("format", getPattern(locale)); - } - - @Override - public String convertToString(LocalTime time, Locale locale) - { - DateTimeFormatter format = getFormat(locale); - return format.format(time); - } - - /** - * @param locale - * The locale used to convert the value - * @return Gets the pattern that is used for printing and parsing - */ - public abstract String getPattern(Locale locale); - - /** - * @param locale - * The locale used to convert the value - * - * @return formatter The formatter for the current conversion - */ - public abstract DateTimeFormatter getFormat(Locale locale); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeTextField.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeTextField.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeTextField.java new file mode 100644 index 0000000..5ea7e3a --- /dev/null +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/LocalTimeTextField.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.extensions.markup.html.form.datetime; + +import java.time.LocalTime; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.FormatStyle; +import java.util.Locale; + +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.convert.converter.LocalTimeConverter; + +/** + * A TextField that is mapped to a <code>java.time.LocalTime</code> object and that uses java.time time to + * parse and format values. + * + * @see java.time.format.DateTimeFormatter + * + * @author eelcohillenius + */ +public class LocalTimeTextField extends TextField<LocalTime> implements ITextFormatProvider +{ + private static final long serialVersionUID = 1L; + + /** + * The converter for the TextField + */ + private final TextFormatConverter converter; + + /** + * Construct with a pattern. + * + * @param id + * the component id + * @param model + * the model + * @param pattern + * the pattern to use + */ + public LocalTimeTextField(String id, IModel<LocalTime> model, String timePattern) + { + super(id, model, LocalTime.class); + + this.converter = new TextFormatConverter() { + + @Override + public DateTimeFormatter getDateTimeFormatter(Locale locale) + { + return DateTimeFormatter.ofPattern(timePattern).withLocale(locale); + } + + @Override + public String getTextFormat(Locale locale) + { + return timePattern; + } + }; + } + + /** + * Construct with a pattern. + * + * @param id + * the component id + * @param pattern + * the pattern to use + */ + public LocalTimeTextField(String id, String datePattern) + { + this(id, null, datePattern); + } + + /** + * Construct with a style. + * + * @param id + * the component id + * @param model + * the model + * @param timeStyle + * the style to use + */ + public LocalTimeTextField(String id, IModel<LocalTime> model, FormatStyle timeStyle) + { + super(id, model, LocalTime.class); + + this.converter = new TextFormatConverter() { + + @Override + public DateTimeFormatter getDateTimeFormatter(Locale locale) + { + return DateTimeFormatter.ofLocalizedTime(timeStyle).withLocale(locale); + } + + @Override + public String getTextFormat(Locale locale) + { + return DateTimeFormatterBuilder.getLocalizedDateTimePattern(null, timeStyle, IsoChronology.INSTANCE, locale); + } + }; + } + + + /** + * Construct with a style. + * + * @param id + * the component id + * @param timeStyle + * the style to use + */ + public LocalTimeTextField(String id, FormatStyle timeStyle) + { + this(id, null, timeStyle); + } + + /** + * @return The specialized converter. + * @see org.apache.wicket.Component#createConverter(java.lang.Class) + */ + @Override + protected IConverter<?> createConverter(Class<?> clazz) + { + if (LocalTime.class.isAssignableFrom(clazz)) + { + return converter; + } + return null; + } + + /** + * @see org.apache.wicket.markup.html.form.AbstractTextComponent.ITextFormatProvider#getTextFormat() + */ + @Override + public final String getTextFormat() + { + return converter.getTextFormat(getLocale()); + } + + private abstract class TextFormatConverter extends LocalTimeConverter { + + public abstract String getTextFormat(Locale locale); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/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 deleted file mode 100644 index 54ea179..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternDateConverter.java +++ /dev/null @@ -1,85 +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.markup.html.form.datetime; - -import java.text.SimpleDateFormat; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -import org.apache.wicket.util.lang.Args; - - -/** - * Date converter that uses javax.time and can be configured to take the time zone difference between - * clients and server into account. This converter is hard coded to use the provided custom date - * pattern, no matter what current locale is used. See {@link SimpleDateFormat} for available - * patterns. - * <p> - * This converter is especially suited on a per-component base. - * </p> - * - * @see SimpleDateFormat - * @see StyleDateConverter - * @see org.apache.wicket.extensions.markup.html.form.DateTextField - * @see java.time.LocalDate - * @see DateTimeFormatter - * - * @author eelcohillenius - */ -public class PatternDateConverter extends LocalDateConverter -{ - - private static final long serialVersionUID = 1L; - - /** pattern to use. */ - private final String datePattern; - - /** - * Construct. - * - * @param datePattern - * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available - * patterns. - * @throws IllegalArgumentException - * in case the date pattern is null - */ - public PatternDateConverter(String datePattern) - { - super(); - this.datePattern = Args.notNull(datePattern, "datePattern"); - } - - /** - * Gets the optional date pattern. - * - * @return datePattern - */ - @Override - public final String getPattern(Locale locale) - { - return datePattern; - } - - /** - * @return formatter The formatter for the current conversion - */ - @Override - public DateTimeFormatter getFormat(Locale locale) - { - return DateTimeFormatter.ofPattern(datePattern).withLocale(locale); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternTimeConverter.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternTimeConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternTimeConverter.java deleted file mode 100644 index 021f500..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternTimeConverter.java +++ /dev/null @@ -1,85 +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.markup.html.form.datetime; - -import java.text.SimpleDateFormat; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -import org.apache.wicket.util.lang.Args; - - -/** - * Date converter that uses javax.time and can be configured to take the time zone difference between - * clients and server into account. This converter is hard coded to use the provided custom date - * pattern, no matter what current locale is used. See {@link SimpleDateFormat} for available - * patterns. - * <p> - * This converter is especially suited on a per-component base. - * </p> - * - * @see SimpleDateFormat - * @see StyleDateConverter - * @see org.apache.wicket.extensions.markup.html.form.DateTextField - * @see java.time.LocalTime - * @see DateTimeFormatter - * - * @author eelcohillenius - */ -public class PatternTimeConverter extends LocalTimeConverter -{ - - private static final long serialVersionUID = 1L; - - /** pattern to use. */ - private final String timePattern; - - /** - * Construct. - * - * @param timePattern - * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available - * patterns. - * @throws IllegalArgumentException - * in case the date pattern is null - */ - public PatternTimeConverter(String timePattern) - { - super(); - this.timePattern = Args.notNull(timePattern, "timePattern"); - } - - /** - * Gets the optional date pattern. - * - * @return datePattern - */ - @Override - public final String getPattern(Locale locale) - { - return timePattern; - } - - /** - * @return formatter The formatter for the current conversion - */ - @Override - public DateTimeFormatter getFormat(Locale locale) - { - return DateTimeFormatter.ofPattern(timePattern).withLocale(locale); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/8567308e/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternZonedDateTimeConverter.java ---------------------------------------------------------------------- diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternZonedDateTimeConverter.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternZonedDateTimeConverter.java deleted file mode 100644 index c432d90..0000000 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/datetime/PatternZonedDateTimeConverter.java +++ /dev/null @@ -1,97 +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.markup.html.form.datetime; - -import java.text.SimpleDateFormat; -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -import org.apache.wicket.util.lang.Args; - - -/** - * Date converter that uses javax.time and can be configured to take the time zone difference between - * clients and server into account. This converter is hard coded to use the provided custom date - * pattern, no matter what current locale is used. See {@link SimpleDateFormat} for available - * patterns. - * <p> - * This converter is especially suited on a per-component base. - * </p> - * - * @see SimpleDateFormat - * @see StyleZonedDateTimeConverter - * @see org.apache.wicket.extensions.markup.html.form.DateTextField - * @see java.time.ZonedDateTime - * @see DateTimeFormatter - * @see java.time.ZoneId - * - * @author eelcohillenius - */ -public class PatternZonedDateTimeConverter extends ZonedDateTimeConverter -{ - - private static final long serialVersionUID = 1L; - - /** pattern to use. */ - private final String datePattern; - - /** - * Construct. - * </p> - * When applyTimeZoneDifference is true, the current time is applied on the parsed date, and the - * date will be corrected for the time zone difference between the server and the client. For - * instance, if I'm in Seattle and the server I'm working on is in Amsterdam, the server is 9 - * hours ahead. So, if I'm inputting say 12/24 at a couple of hours before midnight, at the - * server it is already 12/25. If this boolean is true, it will be transformed to 12/25, while - * the client sees 12/24. - * </p> - * - * @param datePattern - * The pattern to use. Must be not null. See {@link SimpleDateFormat} for available - * patterns. - * @param applyTimeZoneDifference - * whether to apply the difference in time zones between client and server - * @throws IllegalArgumentException - * in case the date pattern is null - */ - public PatternZonedDateTimeConverter(String datePattern, boolean applyTimeZoneDifference) - { - - super(applyTimeZoneDifference); - this.datePattern = Args.notNull(datePattern, "datePattern"); - } - - /** - * Gets the optional date pattern. - * - * @return datePattern - */ - @Override - public final String getPattern(Locale locale) - { - return datePattern; - } - - /** - * @return formatter The formatter for the current conversion - */ - @Override - public DateTimeFormatter getFormat(Locale locale) - { - return DateTimeFormatter.ofPattern(datePattern).withLocale(locale); - } -}
