From c205e4948c6e08e8596edda7d9de46757a75934f Mon Sep 17 00:00:00 2001 From: Francesco Date: Fri, 27 Oct 2023 12:03:44 +0200 Subject: [PATCH] Fixed 'step' attribute value for integer fields; Fixed handling of NumberFormatException --- .../external/dbmapping/DbObjectSchema.java | 2 +- .../external/dbmapping/fields/DbField.java | 16 ++++++++++++++++ .../resources/templates/fragments/inputs.html | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/tech/ailef/dbadmin/external/dbmapping/DbObjectSchema.java b/src/main/java/tech/ailef/dbadmin/external/dbmapping/DbObjectSchema.java index 706724d..04b278d 100644 --- a/src/main/java/tech/ailef/dbadmin/external/dbmapping/DbObjectSchema.java +++ b/src/main/java/tech/ailef/dbadmin/external/dbmapping/DbObjectSchema.java @@ -417,7 +417,7 @@ public class DbObjectSchema { return dbObject; } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new RuntimeException(e); + throw new DbAdminException(e); } } diff --git a/src/main/java/tech/ailef/dbadmin/external/dbmapping/fields/DbField.java b/src/main/java/tech/ailef/dbadmin/external/dbmapping/fields/DbField.java index 7943501..e9ea9e1 100644 --- a/src/main/java/tech/ailef/dbadmin/external/dbmapping/fields/DbField.java +++ b/src/main/java/tech/ailef/dbadmin/external/dbmapping/fields/DbField.java @@ -190,6 +190,22 @@ public class DbField { return type instanceof TextFieldType; } + /** + * Returns the value to use in the "step" HTML attribute + * for numeric data fields. For fields that are not numeric, + * we just return the String "any", as it is not included + * in the HTML template anyway. + * @return + */ + public String getStep() { + if (getType() instanceof IntegerFieldType + || getType() instanceof BigIntegerFieldType + || getType() instanceof ByteFieldType) { + return "0"; + } + return "any"; + } + /** * Returns the name of the Thymeleaf fragment used to render * the input for this field. diff --git a/src/main/resources/templates/fragments/inputs.html b/src/main/resources/templates/fragments/inputs.html index 3b1940b..fc2baaa 100644 --- a/src/main/resources/templates/fragments/inputs.html +++ b/src/main/resources/templates/fragments/inputs.html @@ -56,7 +56,7 @@ (field.isReadOnly() && !create) ? 'disable' : ''}|" th:required="${!field.isNullable() && !field.isPrimaryKey()}" - step="any" + th:step="${field.getStep()}" >