From 22a0434300cfbea4428f7851c7a91a8cd2eabefc Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Mon, 14 Sep 2020 01:14:06 +0300 Subject: [PATCH] Re-format currency field in add/edit web forms Signed-off-by: Pekka Helenius --- .../src/main/java/com/fjordtek/bookstore/model/Book.java | 5 +++-- bookstore/src/main/resources/templates/bookadd.html | 7 ++++++- bookstore/src/main/resources/templates/bookedit.html | 9 +++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java index 73eca8e..3897e06 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java @@ -11,9 +11,10 @@ import javax.validation.constraints.Size; import javax.validation.constraints.Pattern; import javax.validation.constraints.NotNull; -import com.fjordtek.bookstore.validation.CurrentYear; +import com.fjordtek.bookstore.annotation.CurrentYear; import org.springframework.format.annotation.NumberFormat; +import org.springframework.format.annotation.NumberFormat.Style; //import java.sql.Timestamp; //import javax.validation.constraints.PastOrPresent; @@ -114,7 +115,7 @@ public class Book { ) private String isbn; - @NumberFormat(pattern = "#,###,###,###.##") + @NumberFormat(style = Style.NUMBER, pattern = "#,###.###") @Digits( integer = 3, fraction = 2, message = "Invalid price, possibly too many decimals" diff --git a/bookstore/src/main/resources/templates/bookadd.html b/bookstore/src/main/resources/templates/bookadd.html index 9c521ae..0b83f67 100644 --- a/bookstore/src/main/resources/templates/bookadd.html +++ b/bookstore/src/main/resources/templates/bookadd.html @@ -37,7 +37,12 @@
- +
+
+
+
+ +
Set book price
Invalid price
diff --git a/bookstore/src/main/resources/templates/bookedit.html b/bookstore/src/main/resources/templates/bookedit.html index 9fcbf56..6ed382a 100644 --- a/bookstore/src/main/resources/templates/bookedit.html +++ b/bookstore/src/main/resources/templates/bookedit.html @@ -36,8 +36,13 @@
Invalid year
-
- + +
+
+
+
+ +
Set book price
Invalid price