From 43666a2afcc53fa35c6590e04875fdc2d11d9d9d Mon Sep 17 00:00:00 2001 From: Maxim Solodovnik Date: Wed, 18 Oct 2017 10:16:57 +0700 Subject: [PATCH] Examples from modern wicker are being copied, jetty:run is fixed --- .../wicketstuff-portlet-examples/pom.xml | 9 +- .../ajax/builtin/modal/ModalContent1Page.html | 56 ++-- .../ajax/builtin/modal/ModalContent1Page.java | 212 ++++++------ .../ajax/builtin/modal/ModalContent2Page.java | 101 +++--- .../ajax/builtin/modal/ModalPanel1.java | 89 +++-- .../ajax/builtin/modal/ModalWindowPage.java | 261 +++++++-------- .../bean/validation/BeanValidationPage.html | 111 ++++--- .../bean/validation/BeanValidationPage.java | 125 +++---- .../examples/bean/validation/Person.java | 198 +++++------ .../constraint/ValidPasswordValidator.java | 115 ++++--- .../wicket/examples/dates/DatesPage.html | 47 --- .../wicket/examples/dates/DatesPage.java | 219 ------------- .../DateTimeApplication.java} | 83 +++-- .../examples/datetime/DateTimePage.html | 59 ++++ .../examples/datetime/DateTimePage.java | 308 ++++++++++++++++++ .../examples/datetime/DateTimePage.properties | 17 + 16 files changed, 1037 insertions(+), 973 deletions(-) delete mode 100644 portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.html delete mode 100644 portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java rename portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/{dates/DatesApplication.java => datetime/DateTimeApplication.java} (74%) create mode 100644 portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html create mode 100644 portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java create mode 100644 portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties diff --git a/portlet-parent/wicketstuff-portlet-examples/pom.xml b/portlet-parent/wicketstuff-portlet-examples/pom.xml index 942fd8886d..027969fdb8 100644 --- a/portlet-parent/wicketstuff-portlet-examples/pom.xml +++ b/portlet-parent/wicketstuff-portlet-examples/pom.xml @@ -65,10 +65,6 @@ wicket-cdi-1.1 ${wicket.version} - - org.wicketstuff - wicket-datetime - org.apache.wicket wicket-devutils @@ -165,7 +161,7 @@ org.eclipse.jetty.aggregate jetty-all - uber + uber @@ -239,7 +235,6 @@ ${project.build.directory}/test-classes - ${project.basedir}/src/test/jetty/jetty.xml,${project.basedir}/src/test/jetty/jetty-ssl.xml,${project.basedir}/src/test/jetty/jetty-http.xml,${project.basedir}/src/test/jetty/jetty-https.xml @@ -274,7 +269,7 @@ src/main/webapp/WEB-INF/liferay/web.xml - WEB-INF/liferay, + WEB-INF/liferay, WEB-INF/liferay/web.xml, WEB-INF/websphere, WEB-INF/websphere/web.xml, diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.html b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.html index 019c1a29a0..528940efec 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.html +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.html @@ -1,30 +1,28 @@ - - - - This is modal window - - - - Modal WINDOW content. -

- Close this window with result "OK"
- Close this window with result "Cancel"
-

-

-

- Open another modal dialog -

- -

-

An example of a component that uses header contributions
-
-

- - + + + + This is modal window + + + + Modal WINDOW content. +

+ Close this window with result "OK"
+ Close this window with result "Cancel"
+

+

+

+ Open another modal dialog +

+

+

An example of a component that uses header contributions
+
+

+ \ No newline at end of file diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java index 85f0f16d0e..94ba192ebb 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent1Page.java @@ -1,109 +1,103 @@ -/* - * 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.examples.ajax.builtin.modal; - -import org.apache.wicket.Page; -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.markup.html.WebPage; -import org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField; - - -/** - * @author Matej Knopp - * - */ -public class ModalContent1Page extends WebPage -{ - - /** - * - * @param modalWindowPage - * @param window - */ - public ModalContent1Page(final PageReference modalWindowPage, final ModalWindow window) - { - add(new AjaxLink("closeOK") - { - @Override - public void onClick(AjaxRequestTarget target) - { - if (modalWindowPage != null) - ((ModalWindowPage)modalWindowPage.getPage()).setResult("Modal window 1 - close link OK"); - window.close(target); - } - }); - - add(new AjaxLink("closeCancel") - { - @Override - public void onClick(AjaxRequestTarget target) - { - if (modalWindowPage != null) - ((ModalWindowPage)modalWindowPage.getPage()).setResult("Modal window 1 - close link Cancel"); - window.close(target); - } - }); - - add(new DateTimeField("dateTimeField")); - - final ModalWindow modal; - add(modal = new ModalWindow("modal")); - - modal.setCookieName("modal window 2"); - - modal.setResizable(false); - modal.setInitialWidth(30); - modal.setInitialHeight(15); - modal.setWidthUnit("em"); - modal.setHeightUnit("em"); - - modal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); - - modal.setPageCreator(new ModalWindow.PageCreator() - { - @Override - public Page createPage() - { - return new ModalContent2Page(modal); - } - }); - - modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() - { - @Override - public boolean onCloseButtonClicked(AjaxRequestTarget target) - { - target.appendJavaScript("alert('You can\\'t close this modal window using close button." - + " Use the link inside the window instead.');"); - return false; - } - }); - - add(new AjaxLink("open") - { - @Override - public void onClick(AjaxRequestTarget target) - { - modal.show(target); - } - }); - - } -} +/* + * 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.examples.ajax.builtin.modal; + +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.LocalDateTimeField; +import org.apache.wicket.markup.html.WebPage; + + +/** + * @author Matej Knopp + * + */ +public class ModalContent1Page extends WebPage +{ + private static final long serialVersionUID = 1L; + + /** + * + * @param modalWindowPage + * @param window + */ + public ModalContent1Page(final PageReference modalWindowPage, final ModalWindow window) + { + add(new AjaxLink("closeOK") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + if (modalWindowPage != null) + ((ModalWindowPage)modalWindowPage.getPage()).setResult("Modal window 1 - close link OK"); + window.close(target); + } + }); + + add(new AjaxLink("closeCancel") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + if (modalWindowPage != null) + ((ModalWindowPage)modalWindowPage.getPage()).setResult("Modal window 1 - close link Cancel"); + window.close(target); + } + }); + + add(new LocalDateTimeField("dateTimeField")); + + final ModalWindow modal; + add(modal = new ModalWindow("modal")); + + modal.setCookieName("modal window 2"); + + modal.setResizable(false); + modal.setInitialWidth(30); + modal.setInitialHeight(15); + modal.setWidthUnit("em"); + modal.setHeightUnit("em"); + + modal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); + + modal.setPageCreator(() -> new ModalContent2Page(modal)); + + modal.setCloseButtonCallback(target -> { + target.appendJavaScript("alert('You can\\'t close this modal window using close button." + + " Use the link inside the window instead.');"); + return false; + }); + + add(new AjaxLink("open") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + modal.show(target); + } + }); + + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent2Page.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent2Page.java index bdd788892e..4b668acd38 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent2Page.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalContent2Page.java @@ -1,52 +1,49 @@ -/* - * 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.examples.ajax.builtin.modal; - -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.markup.html.WebPage; - - -/** - * @author Matej Knopp - * - */ -public class ModalContent2Page extends WebPage -{ - - /** - * @param window - */ - public ModalContent2Page(final ModalWindow window) - { - add(new AjaxLink("close") - { - private static final long serialVersionUID = 1L; - - @Override - public void onClick(AjaxRequestTarget target) - { - window.close(target); - } - }); - - - } - - -} +/* + * 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.examples.ajax.builtin.modal; + +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.markup.html.WebPage; + + +/** + * @author Matej Knopp + * + */ +public class ModalContent2Page extends WebPage +{ + private static final long serialVersionUID = 1L; + + /** + * @param window + */ + public ModalContent2Page(final ModalWindow window) + { + add(new AjaxLink("close") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + window.close(target); + } + }); + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java index ef77eedb1c..884077cf14 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalPanel1.java @@ -1,52 +1,37 @@ -/* - * 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.examples.ajax.builtin.modal; - -import java.util.Map; - -import org.apache.wicket.markup.html.panel.Panel; -import org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField; - -/** - * @author Matej Knopp - */ -public class ModalPanel1 extends Panel -{ - - /** - * @param id - */ - public ModalPanel1(String id) - { - super(id); - - add(new DateTimeField("dateTimeField") - { - /** - * @see org.apache.wicket.extensions.yui.calendar.DateTimeField#configure(java.util.Map) - */ - @Override - protected void configure(Map widgetProperties) - { - super.configure(widgetProperties); - // IE 6 breaks layout with iframe - is that a YUI bug? - widgetProperties.put("iframe", false); - } - }); - } - -} +/* + * 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.examples.ajax.builtin.modal; + +import org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTimeField; +import org.apache.wicket.markup.html.panel.Panel; + +/** + * @author Matej Knopp + */ +public class ModalPanel1 extends Panel +{ + private static final long serialVersionUID = 1L; + + /** + * @param id + */ + public ModalPanel1(String id) + { + super(id); + add(new LocalDateTimeField("dateTimeField")); + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalWindowPage.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalWindowPage.java index 32b560e628..f8376fffdd 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalWindowPage.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/ajax/builtin/modal/ModalWindowPage.java @@ -1,145 +1,116 @@ -/* - * 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.examples.ajax.builtin.modal; - -import org.apache.wicket.Page; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.markup.html.AjaxLink; -import org.apache.wicket.examples.ajax.builtin.BasePage; -import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; -import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.model.PropertyModel; - - -/** - * @author Matej Knopp - */ -public class ModalWindowPage extends BasePage -{ - - /** - */ - public ModalWindowPage() - { - final Label result; - add(result = new Label("result", new PropertyModel<>(this, "result"))); - result.setOutputMarkupId(true); - - /* - * First modal window - */ - - final ModalWindow modal1; - add(modal1 = new ModalWindow("modal1")); - - modal1.setCookieName("modal-1"); - - modal1.setPageCreator(new ModalWindow.PageCreator() - { - @Override - public Page createPage() - { - return new ModalContent1Page(ModalWindowPage.this.getPageReference(), modal1); - } - }); - modal1.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() - { - @Override - public void onClose(AjaxRequestTarget target) - { - target.add(result); - } - }); - modal1.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() - { - @Override - public boolean onCloseButtonClicked(AjaxRequestTarget target) - { - setResult("Modal window 1 - close button"); - return true; - } - }); - - add(new AjaxLink("showModal1") - { - @Override - public void onClick(AjaxRequestTarget target) - { - modal1.show(target); - } - }); - - /* - * Second modal window - */ - - final ModalWindow modal2; - add(modal2 = new ModalWindow("modal2")); - - modal2.setContent(new ModalPanel1(modal2.getContentId())); - modal2.setTitle("This is modal window with panel content."); - modal2.setCookieName("modal-2"); - - modal2.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() - { - @Override - public boolean onCloseButtonClicked(AjaxRequestTarget target) - { - setResult("Modal window 2 - close button"); - return true; - } - }); - - modal2.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() - { - @Override - public void onClose(AjaxRequestTarget target) - { - target.add(result); - } - }); - - add(new AjaxLink("showModal2") - { - @Override - public void onClick(AjaxRequestTarget target) - { - modal2.show(target); - } - }); - } - - /** - * @return the result - */ - public String getResult() - { - return result; - } - - /** - * @param result - * the result to set - */ - public void setResult(String result) - { - this.result = result; - } - - private String result; - -} +/* + * 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.examples.ajax.builtin.modal; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.examples.ajax.builtin.BasePage; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.model.PropertyModel; + + +/** + * @author Matej Knopp + */ +public class ModalWindowPage extends BasePage +{ + private static final long serialVersionUID = 1L; + + public ModalWindowPage() + { + final Label result; + add(result = new Label("result", new PropertyModel<>(this, "result"))); + result.setOutputMarkupId(true); + + /* + * First modal window + */ + + final ModalWindow modal1; + add(modal1 = new ModalWindow("modal1")); + + modal1.setCookieName("modal-1"); + + modal1.setPageCreator(() -> new ModalContent1Page(ModalWindowPage.this.getPageReference(), modal1)); + modal1.setWindowClosedCallback(target -> target.add(result)); + modal1.setCloseButtonCallback(target -> { + setResult("Modal window 1 - close button"); + return true; + }); + + add(new AjaxLink("showModal1") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + modal1.show(target); + } + }); + + /* + * Second modal window + */ + + final ModalWindow modal2; + add(modal2 = new ModalWindow("modal2")); + + modal2.setContent(new ModalPanel1(modal2.getContentId())); + modal2.setTitle("Modal window\n'panel\" content."); + modal2.setCookieName("modal-2"); + + modal2.setCloseButtonCallback(target -> { + setResult("Modal window 2 - close button"); + return true; + }); + + modal2.setWindowClosedCallback(target -> target.add(result)); + + add(new AjaxLink("showModal2") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + modal2.show(target); + } + }); + } + + /** + * @return the result + */ + public String getResult() + { + return result; + } + + /** + * @param result + * the result to set + */ + public void setResult(String result) + { + this.result = result; + } + + private String result; + +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html index 78ca79257f..7b5f6fa6bb 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.html @@ -1,54 +1,57 @@ - - -Wicket Examples - Bean Validation - - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@NotNull @Size(min = 2, max = 30)
@NotNull @Email
@Pattern(regexp = "[0-9]{3}-[0-9]{4}")
m/d/yyyy field with @Past
Custom constraint @ValidPassword with custom message bundles.
A valid password must contain only alphanumeric chars and at least two digits.
-
- - press to submit the form and run the validation
-
-
- - + + +Wicket Examples - Bean Validation + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@NotNull @Size(min = 2, max = 30)
@NotNull @Email
@Pattern(regexp = "[0-9]{3}-[0-9]{4}")
 field with @Past
+
Custom constraint @ValidPassword with custom message bundles.
A valid password must contain only alphanumeric chars and at least two digits.
+
+ + press to submit the form and run the validation
+
+
+ + diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java index 57a6a59eb1..317386763c 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/BeanValidationPage.java @@ -1,61 +1,64 @@ -/* - * 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.examples.bean.validation; - -import java.util.Date; - -import org.apache.wicket.bean.validation.PropertyValidator; -import org.apache.wicket.examples.WicketExamplePage; -import org.apache.wicket.feedback.ExactLevelFeedbackMessageFilter; -import org.apache.wicket.feedback.FeedbackMessage; -import org.apache.wicket.markup.html.form.Form; -import org.apache.wicket.markup.html.form.TextField; -import org.apache.wicket.markup.html.panel.FeedbackPanel; -import org.apache.wicket.model.PropertyModel; -import org.wicketstuff.datetime.StyleDateConverter; -import org.wicketstuff.datetime.markup.html.form.DateTextField; - -public class BeanValidationPage extends WicketExamplePage -{ - - Person person = new Person(); - - public BeanValidationPage() - { - add(new FeedbackPanel("feedbackErrors", new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR))); - - Form form = new Form("form") { - @Override - protected void onSubmit() - { - super.onSubmit(); - info("Form successfully submitted!"); - } - }; - - add(form); - - form.add(new TextField("name", new PropertyModel(this, "person.name")).add(new PropertyValidator<>())); - form.add(new TextField("phone", new PropertyModel(this, "person.phone")).add(new PropertyValidator<>())); - form.add(new TextField("email", new PropertyModel(this, "person.email")).add(new PropertyValidator<>())); - form.add(new DateTextField("birthdate", new PropertyModel(this, "person.birthdate"), - new StyleDateConverter("S-", true)).add(new PropertyValidator<>())); - form.add(new TextField("password", new PropertyModel(this, "person.password")).add(new PropertyValidator<>())); - - add(new FeedbackPanel("feedbackSuccess", new ExactLevelFeedbackMessageFilter(FeedbackMessage.INFO))); - } -} \ No newline at end of file +/* + * 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.examples.bean.validation; + +import java.time.format.FormatStyle; + +import org.apache.wicket.bean.validation.PropertyValidator; +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; +import org.apache.wicket.model.PropertyModel; + +public class BeanValidationPage extends WicketExamplePage +{ + private static final long serialVersionUID = 1L; + Person person = new Person(); + + public BeanValidationPage() + { + add(new FeedbackPanel("feedbackErrors", new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR))); + + Form form = new Form("form") { + private static final long serialVersionUID = 1L; + + @Override + protected void onSubmit() + { + super.onSubmit(); + info("Form successfully submitted!"); + } + }; + + add(form); + + form.add(new TextField<>("name", new PropertyModel(this, "person.name")).add(new PropertyValidator<>())); + form.add(new TextField<>("phone", new PropertyModel(this, "person.phone")).add(new PropertyValidator<>())); + form.add(new TextField<>("email", new PropertyModel(this, "person.email")).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(this, "person.password")).add(new PropertyValidator<>())); + + add(new FeedbackPanel("feedbackSuccess", new ExactLevelFeedbackMessageFilter(FeedbackMessage.INFO))); + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/Person.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/Person.java index 2cb10b565b..feb056492d 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/Person.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/Person.java @@ -1,98 +1,100 @@ -/* - * 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.examples.bean.validation; - -import java.io.Serializable; -import java.util.Date; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Past; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - -import org.apache.wicket.examples.bean.validation.constraint.ValidPassword; -import org.hibernate.validator.constraints.Email; - -public class Person implements Serializable -{ - @NotNull - @Size(min = 2, max = 30) - private String name; - - @NotNull - @Email - private String email; - - @Pattern(regexp = "[0-9]{3}-[0-9]{4}") - private String phone; - - @Past - private Date birthdate; - - @ValidPassword - private String password; - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public String getEmail() - { - return email; - } - - public void setEmail(String email) - { - this.email = email; - } - - public String getPhone() - { - return phone; - } - - public void setPhone(String phone) - { - this.phone = phone; - } - - public Date getBirthdate() - { - return birthdate; - } - - public void setBirthdate(Date birthdate) - { - this.birthdate = birthdate; - } - - public String getPassword() - { - return password; - } - - public void setPassword(String password) - { - this.password = password; - } -} +/* + * 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.examples.bean.validation; + +import java.io.Serializable; +import java.time.LocalDate; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Past; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; + +import org.apache.wicket.examples.bean.validation.constraint.ValidPassword; + +public class Person implements Serializable +{ + private static final long serialVersionUID = 1L; + + @NotNull + @Size(min = 2, max = 30) + private String name; + + @NotNull + @Email + private String email; + + @Pattern(regexp = "[0-9]{3}-[0-9]{4}") + private String phone; + + @Past + private LocalDate birthdate; + + @ValidPassword + private String password; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getEmail() + { + return email; + } + + public void setEmail(String email) + { + this.email = email; + } + + public String getPhone() + { + return phone; + } + + public void setPhone(String phone) + { + this.phone = phone; + } + + public LocalDate getBirthdate() + { + return birthdate; + } + + public void setBirthdate(LocalDate birthdate) + { + this.birthdate = birthdate; + } + + public String getPassword() + { + return password; + } + + public void setPassword(String password) + { + this.password = password; + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/constraint/ValidPasswordValidator.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/constraint/ValidPasswordValidator.java index 68b5d092ef..1b68dd38c3 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/constraint/ValidPasswordValidator.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/bean/validation/constraint/ValidPasswordValidator.java @@ -1,58 +1,57 @@ -/* - * 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.examples.bean.validation.constraint; - -import java.util.regex.Pattern; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - - -public class ValidPasswordValidator implements ConstraintValidator -{ - - private final Pattern content = Pattern.compile("[0-9a-zA-Z]*"); - private final Pattern digits = Pattern.compile("(.*\\d.*){2}"); - - @Override - public void initialize(ValidPassword constraintAnnotation) - { - - } - - @Override - public boolean isValid(String value, ConstraintValidatorContext context) - { - boolean validationResult = true; - - if (!content.matcher(value).matches()) - { - validationResult = false; - } - else if (!digits.matcher(value).matches()) - { - context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("{password.needDigits}") - .addConstraintViolation(); - - validationResult = false; - } - - return validationResult; - } - -} +/* + * 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.examples.bean.validation.constraint; + +import java.util.regex.Pattern; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + + +public class ValidPasswordValidator implements ConstraintValidator +{ + private static final Pattern CONTENT = Pattern.compile("[0-9a-zA-Z]*"); + private static final Pattern DIGITS = Pattern.compile("(.*\\d.*){2}"); + + @Override + public void initialize(ValidPassword constraintAnnotation) + { + + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) + { + boolean validationResult = true; + + if (!CONTENT.matcher(value).matches()) + { + validationResult = false; + } + else if (!DIGITS.matcher(value).matches()) + { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate("{password.needDigits}") + .addConstraintViolation(); + + validationResult = false; + } + + return validationResult; + } + +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.html b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.html deleted file mode 100644 index 183edc56e0..0000000000 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - Wicket Examples - dates - - - - - -
-

-

- -
-

- Example using DateTimeField:  -

- - -
-

- -
-

- Example using TimeField:  -

- - -
-

- -

-

-

- - - diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java deleted file mode 100644 index c59fc7c215..0000000000 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesPage.java +++ /dev/null @@ -1,219 +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.examples.dates; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import org.apache.wicket.Session; -import org.apache.wicket.examples.WicketExamplePage; -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.link.Link; -import org.apache.wicket.markup.html.panel.FeedbackPanel; -import org.apache.wicket.model.AbstractReadOnlyModel; -import org.apache.wicket.model.PropertyModel; -import org.wicketstuff.datetime.StyleDateConverter; -import org.wicketstuff.datetime.extensions.yui.calendar.DatePicker; -import org.wicketstuff.datetime.extensions.yui.calendar.DateTimeField; -import org.wicketstuff.datetime.extensions.yui.calendar.TimeField; -import org.wicketstuff.datetime.markup.html.form.DateTextField; - -/** - * Demonstrates components from the wicket-date project and a bunch of locale fiddling. - */ -public class DatesPage extends WicketExamplePage -{ - /** - * Choice for a locale. - */ - private final class LocaleChoiceRenderer extends ChoiceRenderer - { - /** - * Constructor. - */ - public LocaleChoiceRenderer() - { - } - - /** - * @see org.apache.wicket.markup.html.form.IChoiceRenderer#getDisplayValue(Object) - */ - @Override - public Object getDisplayValue(Locale locale) - { - String enName = locale.getDisplayName(LOCALE_EN); - String localizedName = locale.getDisplayName(selectedLocale); - return localizedName + (!enName.equals(localizedName) ? (" (" + enName + ")") : ""); - } - } - - /** - * Dropdown with Locales. - */ - private final class LocaleDropDownChoice extends DropDownChoice - { - /** - * Construct. - * - * @param id - * component id - */ - public LocaleDropDownChoice(String id) - { - super(id); - // sort locales on strings of selected locale - setChoices(new AbstractReadOnlyModel>() - { - @Override - public List getObject() - { - List locales = new ArrayList<>(LOCALES); - Collections.sort(locales, new Comparator() - { - @Override - public int compare(Locale o1, Locale o2) - { - return o1.getDisplayName(selectedLocale).compareTo( - o2.getDisplayName(selectedLocale)); - } - }); - return locales; - } - }); - setChoiceRenderer(new LocaleChoiceRenderer()); - setDefaultModel(new PropertyModel<>(DatesPage.this, "selectedLocale")); - add(new FormComponentUpdatingBehavior()); - } - } - - private static final Locale LOCALE_EN = new Locale("en"); - - private static final List LOCALES; - static - { - LOCALES = Arrays.asList(Locale.getAvailableLocales()); - } - - /** the backing object for DateTextField demo */ - private final Date date = new Date(); - - /** the backing object for DateTimeField demo */ - private final Date date2 = new Date(); - - /** the backing object for TimeField demo */ - private final Date time = new Date(); - - private Locale selectedLocale = LOCALE_EN; - - /** - * Constructor - */ - public DatesPage() - { - selectedLocale = Session.get().getLocale(); - Form localeForm = new Form<>("localeForm"); - localeForm.add(new LocaleDropDownChoice("localeSelect")); - localeForm.add(new Link("localeUSLink") - { - @Override - public void onClick() - { - selectedLocale = LOCALE_EN; - } - }); - add(localeForm); - DateTextField dateTextField = new DateTextField("dateTextField", new PropertyModel( - this, "date"), new StyleDateConverter("S-", true)) - { - @Override - public Locale getLocale() - { - return selectedLocale; - } - }; - Form form = new Form("form") - { - @Override - protected void onSubmit() - { - info("set date to " + date); - } - }; - add(form); - form.add(dateTextField); - - DatePicker datePicker = new DatePicker() - { - @Override - protected String getAdditionalJavaScript() - { - return "${calendar}.cfg.setProperty(\"navigator\",true,false); ${calendar}.render();"; - } - }; - datePicker.setShowOnFieldClick(true); - datePicker.setAutoHide(true); - dateTextField.add(datePicker); - add(new FeedbackPanel("feedback")); - - Form form2 = new Form("form2") - { - @Override - protected void onSubmit() - { - info("set date2 to " + date2); - } - }; - add(form2); - form2.add(new DateTimeField("dateTimeField", new PropertyModel(this, "date2"))); - - - Form form3 = new Form("form3") - { - @Override - protected void onSubmit() - { - info("set time to " + time); - } - }; - add(form3); - form3.add(new TimeField("timeField", new PropertyModel(this, "time"))); - } - - /** - * @return the selected locale - */ - public final Locale getSelectedLocale() - { - return selectedLocale; - } - - /** - * @param selectedLocale - */ - public final void setSelectedLocale(Locale selectedLocale) - { - this.selectedLocale = selectedLocale; - } -} \ No newline at end of file diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesApplication.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java similarity index 74% rename from portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesApplication.java rename to portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java index 9efdb4ca11..fa29a219ed 100644 --- a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/dates/DatesApplication.java +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimeApplication.java @@ -1,42 +1,41 @@ -/* - * 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.examples.dates; - -import org.apache.wicket.Page; -import org.apache.wicket.examples.WicketExampleApplication; - -/** - * Application class for the dates example. - */ -public class DatesApplication extends WicketExampleApplication -{ - /** - * Constructor. - */ - public DatesApplication() - { - } - - /** - * @see org.apache.wicket.Application#getHomePage() - */ - @Override - public Class< ? extends Page> getHomePage() - { - return DatesPage.class; - } -} +/* + * 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.examples.datetime; + +import org.apache.wicket.Page; +import org.apache.wicket.examples.WicketExampleApplication; + +/** + * Application class for the DateTime example. + * + */ +public class DateTimeApplication extends WicketExampleApplication +{ + @Override + protected void init() + { + super.init(); + + getRequestCycleSettings().setGatherExtendedBrowserInfo(true); + } + + @Override + public Class< ? extends Page> getHomePage() + { + return DateTimePage.class; + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html new file mode 100644 index 0000000000..2589935745 --- /dev/null +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.html @@ -0,0 +1,59 @@ + + + + Wicket Examples - DateTime + + + + + +
+
+ + + [] +
+ +
+ +

TimeField 12-hours

+
+ +
+ +

TimeField 24-hours

+
+ +
+ +

LocalDateTimeField (default time 00:00)

+
+ +
+ + + +
+ +

LocalDateTimeField with a ZonedDateTime () adjusted to client's time zone

+ +
+ +

LocalDateTimeTextField with a ZonedDateTime () adjusted to client's time zone

+ +
+ +

ZonedDateTimeField

+ +
+ +
+ +
+ + +
+ + diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java new file mode 100644 index 0000000000..de0f8ea7df --- /dev/null +++ b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.java @@ -0,0 +1,308 @@ +/* + * 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.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.Session; +import org.apache.wicket.examples.WicketExamplePage; +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.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. + * + */ +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() + { + Form 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("defaultLocaleLink") + { + private static final long serialVersionUID = 1L; + + 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() + { + return false; + } + }); + + final LocalDateTimeField datetimeField0 = new LocalDateTimeField("datetime0", + new PropertyModel<>(this, "dateTime0")) + { + private static final long serialVersionUID = 1L; + + @Override + protected LocalTime getDefaultTime() + { + return LocalTime.of(0, 0); + } + }; + form.add(datetimeField0); + + IModel zonedDateTime1 = new PropertyModel<>(this, "dateTime1"); + final LocalDateTimeField datetimeField1 = new LocalDateTimeField("datetime1", + new ZonedToLocalDateTimeModel(zonedDateTime1) + { + private static final long serialVersionUID = 1L; + + @Override + protected ZoneId getClientTimeZone() + { + return clientZone; + } + + @Override + protected ZoneId getTargetTimeZone() + { + return targetZone; + } + }); + form.add(datetimeField1); + form.add(new Label("datetime1-label", zonedDateTime1)); + + IModel zonedDateTime2 = new PropertyModel<>(this, "dateTime2"); + LocalDateTimeTextField datetime2 = new LocalDateTimeTextField("datetime2", + new ZonedToLocalDateTimeModel(zonedDateTime2) + { + private static final long serialVersionUID = 1L; + + @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.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 + { + private static final long serialVersionUID = 1L; + + @Override + public Object getDisplayValue(Locale locale) + { + return locale.getDisplayName(getLocale()); + } + } + + /** + * Dropdown with Locales. + */ + private final class LocaleDropDownChoice extends DropDownChoice + { + private static final long serialVersionUID = 1L; + + /** + * Construct. + * + * @param id + * component id + */ + public LocaleDropDownChoice(String id) + { + super(id, FormInputApplication.LOCALES, new LocaleChoiceRenderer()); + + setModel(new PropertyModel<>(this, "session.locale")); + + add(new FormComponentUpdatingBehavior() + { + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate() + { + setResponsePage(getPage().getClass()); + } + }); + } + } + + private class ZoneDropDownChoice extends DropDownChoice + { + private static final long serialVersionUID = 1L; + + public ZoneDropDownChoice(String id) + { + super(id, new IModel>() + { + private static final long serialVersionUID = 1L; + + @Override + public List getObject() + { + return ZoneId.getAvailableZoneIds().stream().map(id -> ZoneId.of(id)) + .collect(Collectors.toList()); + } + }); + + setModel(new PropertyModel(DateTimePage.this, "clientZone")); + + setChoiceRenderer(new IChoiceRenderer() + { + private static final long serialVersionUID = 1L; + + @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> choices) + { + return ZoneId.of(id); + } + }); + + add(new FormComponentUpdatingBehavior() + { + private static final long serialVersionUID = 1L; + + protected void onUpdate() + { + // clear raw input of all inputs so that values are reformatted + getForm().clearInput(); + }; + }); + } + } +} diff --git a/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties b/portlet-parent/wicketstuff-portlet-examples/src/main/java/org/apache/wicket/examples/datetime/DateTimePage.properties new file mode 100644 index 0000000000..6a4447b3d5 --- /dev/null +++ b/portlet-parent/wicketstuff-portlet-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