From 7a22d4bb14aa1526e56cb211b84db00e4ff3a0e2 Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Fri, 18 Sep 2020 22:33:18 +0300 Subject: [PATCH] Use Thymeleaf message expressions in web forms Signed-off-by: Pekka Helenius --- .../bookstore/web/BookController.java | 4 -- .../src/main/resources/messages.properties | 41 ++++++++++++++ .../src/main/resources/templates/bookadd.html | 54 +++++++++++-------- .../main/resources/templates/bookedit.html | 52 ++++++++++-------- .../main/resources/templates/booklist.html | 26 ++++----- 5 files changed, 117 insertions(+), 60 deletions(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java index 4a3cd36..acd9ba2 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java @@ -35,8 +35,6 @@ public class BookController { private static final String bookDeletePageView = "bookdelete"; private static final String bookEditPageView = "bookedit"; - private static String currency_symbol = "€"; - private Map globalModelMap = new HashMap() { private static final long serialVersionUID = 1L; { @@ -45,8 +43,6 @@ public class BookController { put("addpage", bookAddPageView); put("deletepage", bookDeletePageView); put("editpage", bookEditPageView); - - put("currency_symbol", currency_symbol); }}; private HttpServerLogger httpServerLogger = new HttpServerLogger(); diff --git a/bookstore/src/main/resources/messages.properties b/bookstore/src/main/resources/messages.properties index 763e544..122cdf2 100644 --- a/bookstore/src/main/resources/messages.properties +++ b/bookstore/src/main/resources/messages.properties @@ -1,2 +1,43 @@ +# Keep as fall back values if multi-language support is added + typeMismatch.book.year = Invalid year format typeMismatch.book.price = Invalid price format + +book.author = Author +book.title = Title +book.isbn = ISBN +book.year = Year +book.price = Price +book.category = Category + +book.desc.set.author = Set book author name +book.desc.set.title = Set book primary title +book.desc.set.isbn = Set book ISBN code +book.desc.set.year = Set book publication year +book.desc.set.price = Set book price +book.desc.set.category = Select appropriate category + +book.error.author = Invalid author name +book.error.title = Invalid title +book.error.isbn = Invalid ISBN code +book.error.year = Invalid year +book.error.price = Invalid price + +page.title.browser.list = Bookstore page +page.title.browser.add = Add book +page.title.browser.edit = Update book + +page.title.webform.list = Books +page.title.webform.add = Add new book +page.title.webform.edit = Update existing book + +page.text.list.actions = Actions +page.text.list.delete = Delete +page.text.list.edit = Edit + +button.book.add = Add book +button.book.edit = Update book + +button.page.list.return = Return to book list page + +page.symbols.currency = \u20AC \ No newline at end of file diff --git a/bookstore/src/main/resources/templates/bookadd.html b/bookstore/src/main/resources/templates/bookadd.html index fee13cd..bd4209b 100644 --- a/bookstore/src/main/resources/templates/bookadd.html +++ b/bookstore/src/main/resources/templates/bookadd.html @@ -3,51 +3,61 @@ - Add new book +
-

Add new book

+

- + - Set book author name -
Invalid author name
+ +
Invalid author name
+
- + - Set book primary title -
Invalid title
+ +
Invalid title
+
- + - Set book ISBN code -
Invalid ISBN code
+ +
Invalid ISBN code
+
- + - Set book publication year -
Invalid year
+ +
Invalid year
+
- +
-
+
- Set book price -
Invalid price
+ +
Invalid price
+
- + - Select appropriate category +
- +

- +
diff --git a/bookstore/src/main/resources/templates/bookedit.html b/bookstore/src/main/resources/templates/bookedit.html index 7f6243e..365f38b 100644 --- a/bookstore/src/main/resources/templates/bookedit.html +++ b/bookstore/src/main/resources/templates/bookedit.html @@ -3,48 +3,57 @@ - Update existing book +
-

Update existing book

+

-
+
- Set book author name -
Invalid author name
+ +
Invalid author name
+
-
+
- Set book primary title -
Invalid title
+ +
Invalid title
+
-
+
- Set book ISBN code -
Invalid ISBN code
+ +
Invalid ISBN code
+
-
+
- Set book publication year -
Invalid year
+ +
Invalid year
+
- +
-
+
- Set book price -
Invalid price
+ +
Invalid price
@@ -56,14 +65,15 @@ th:text="${category.getName()}" > - Select appropriate category +
- +
+
- +
diff --git a/bookstore/src/main/resources/templates/booklist.html b/bookstore/src/main/resources/templates/booklist.html index e52db44..5bd1485 100644 --- a/bookstore/src/main/resources/templates/booklist.html +++ b/bookstore/src/main/resources/templates/booklist.html @@ -3,21 +3,21 @@ - Bookstore page +
-

Books

+

- - - - - - - + + + + + + + @@ -26,16 +26,16 @@ - + + th:href="@{__${deletepage}__/{id}(id=${book.id})}" th:text="#{page.text.list.delete}"> + th:href="@{__${editpage}__/{id}(id=${book.id})}" th:text="#{page.text.list.edit}">
AuthorTitleISBNYearCategoryPriceActions
Delete Edit
- Add Book +