You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/04/09 18:44:55 UTC
[isis] 01/02: ISIS-2063: Entering a string such as 10:45 for a joda
LocalTime causes stack trace
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 2af0a8161a47ebbc7c1a0873be84e0b8b9de6890
Author: joonatan-r <jo...@student.lut.fi>
AuthorDate: Fri Apr 9 18:41:13 2021 +0300
ISIS-2063: Entering a string such as 10:45 for a joda LocalTime causes stack trace
Without this patch applied, input to a joda LocalTime field causes an error.
This patch fixes the problem by adding a panel to be used by joda LocalTime.
---
.../jodatime/ConverterForJodaLocalTime.java | 43 ++++++++++++++++
.../scalars/jodatime/JodaLocalTimePanel.java | 59 ++++++++++++++++++++++
.../jodatime/JodaLocalTimePanelFactory.java | 43 ++++++++++++++++
.../ComponentFactoryRegistrarDefault.java | 2 +
4 files changed, 147 insertions(+)
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/ConverterForJodaLocalTime.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/ConverterForJodaLocalTime.java
new file mode 100644
index 0000000..84978db
--- /dev/null
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/ConverterForJodaLocalTime.java
@@ -0,0 +1,43 @@
+/*
+ * 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.isis.viewer.wicket.ui.components.scalars.jodatime;
+
+import org.apache.wicket.util.convert.ConversionException;
+import org.apache.wicket.util.convert.IConverter;
+import org.joda.time.LocalTime;
+
+import java.util.Locale;
+
+public class ConverterForJodaLocalTime implements IConverter<LocalTime> {
+
+ private static final long serialVersionUID = 1L;
+
+ public LocalTime convertToObject(String value, Locale locale) throws ConversionException {
+ try {
+ return LocalTime.parse(value);
+ } catch (Exception e) {
+ throw new ConversionException("'" + value + "' is not a valid time.");
+ }
+ }
+
+ public String convertToString(LocalTime value, Locale locale) {
+ return value.toString();
+ }
+}
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/JodaLocalTimePanel.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/JodaLocalTimePanel.java
new file mode 100644
index 0000000..2434193
--- /dev/null
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/JodaLocalTimePanel.java
@@ -0,0 +1,59 @@
+/*
+ * 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.isis.viewer.wicket.ui.components.scalars.jodatime;
+
+import org.apache.isis.viewer.wicket.model.models.ScalarModel;
+import org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelTextFieldAbstract;
+import org.apache.isis.viewer.wicket.ui.components.scalars.TextFieldValueModel;
+import org.apache.wicket.markup.html.form.AbstractTextComponent;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.util.convert.IConverter;
+import org.joda.time.LocalTime;
+
+/**
+ * Panel for rendering scalars of type {@link LocalTime}.
+ */
+public class JodaLocalTimePanel extends ScalarPanelTextFieldAbstract<LocalTime> {
+
+ private static final long serialVersionUID = 1L;
+
+ public JodaLocalTimePanel(final String id, final ScalarModel scalarModel) {
+ super(id, scalarModel, LocalTime.class);
+ }
+
+ @Override
+ protected AbstractTextComponent<LocalTime> createTextFieldForRegular(final String id) {
+ final TextFieldValueModel<LocalTime> textFieldValueModel = new TextFieldValueModel<>(this);
+ return new TextField<LocalTime>(id, textFieldValueModel, LocalTime.class) {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C> IConverter<C> getConverter(Class<C> type) {
+ return (IConverter<C>) (type == LocalTime.class ? new ConverterForJodaLocalTime() : super.getConverter(type));
+ }
+ };
+ }
+
+ @Override
+ protected String getScalarPanelType() {
+ return "jodaLocalTimePanel";
+ }
+}
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/JodaLocalTimePanelFactory.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/JodaLocalTimePanelFactory.java
new file mode 100644
index 0000000..10e3293
--- /dev/null
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/jodatime/JodaLocalTimePanelFactory.java
@@ -0,0 +1,43 @@
+/*
+ * 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.isis.viewer.wicket.ui.components.scalars.jodatime;
+
+import org.apache.isis.viewer.wicket.model.models.ScalarModel;
+import org.apache.isis.viewer.wicket.ui.ComponentFactory;
+import org.apache.isis.viewer.wicket.ui.components.scalars.ComponentFactoryScalarAbstract;
+import org.apache.wicket.Component;
+import org.joda.time.LocalTime;
+
+/**
+ * {@link ComponentFactory} for {@link JodaLocalTimePanel}.
+ */
+public class JodaLocalTimePanelFactory extends ComponentFactoryScalarAbstract {
+
+ private static final long serialVersionUID = 1L;
+
+ public JodaLocalTimePanelFactory() {
+ super(JodaLocalTimePanel.class, LocalTime.class);
+ }
+
+ @Override
+ public Component createComponent(final String id, final ScalarModel scalarModel) {
+ return new JodaLocalTimePanel(id, scalarModel);
+ }
+}
diff --git a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistrarDefault.java b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistrarDefault.java
index b00775f..7edb75e 100644
--- a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistrarDefault.java
+++ b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistrarDefault.java
@@ -65,6 +65,7 @@ import org.apache.isis.viewer.wicket.ui.components.scalars.jdkmath.JavaMathBigIn
import org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.JodaDateTimePanelFactory;
import org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.JodaLocalDatePanelFactory;
import org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.JodaLocalDateTimePanelFactory;
+import org.apache.isis.viewer.wicket.ui.components.scalars.jodatime.JodaLocalTimePanelFactory;
import org.apache.isis.viewer.wicket.ui.components.scalars.markup.MarkupPanelFactories;
import org.apache.isis.viewer.wicket.ui.components.scalars.oiddto.OidDtoPanelFactory;
import org.apache.isis.viewer.wicket.ui.components.scalars.passwd.IsisPasswordPanelFactory;
@@ -252,6 +253,7 @@ public class ComponentFactoryRegistrarDefault implements ComponentFactoryRegistr
componentFactories.add(new JodaLocalDatePanelFactory());
componentFactories.add(new JodaLocalDateTimePanelFactory());
+ componentFactories.add(new JodaLocalTimePanelFactory());
componentFactories.add(new JodaDateTimePanelFactory());
componentFactories.add(new Jdk8OffsetDateTimePanelFactory());