From 382c8e9136ee0c1bb497bf2f50d17345f6458e2c Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Fri, 18 Sep 2020 01:59:15 +0300 Subject: [PATCH] Generalize web form URL scheme Signed-off-by: Pekka Helenius --- .../bookstore/web/BookController.java | 32 +++++++++++++------ .../src/main/resources/templates/bookadd.html | 2 +- .../main/resources/templates/bookedit.html | 2 +- .../main/resources/templates/booklist.html | 4 +-- 4 files changed, 27 insertions(+), 13 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 f40e015..26cb4c3 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java @@ -3,6 +3,8 @@ package com.fjordtek.bookstore.web; import java.time.Year; +import java.util.HashMap; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; @@ -32,6 +34,20 @@ 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; + { + put("indexpage", landingPageView); + put("listpage", bookListPageView); + put("addpage", bookAddPageView); + put("deletepage", bookDeletePageView); + put("editpage", bookEditPageView); + + put("currency_symbol", currency_symbol); + }}; + private HttpServerLogger httpServerLogger = new HttpServerLogger(); //private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler(); @@ -41,6 +57,13 @@ public class BookController { @Autowired private CategoryRepository categoryRepository; + @ModelAttribute + public void globalAttributes(Model dataModel) { + + // Security implications of adding these all? + dataModel.addAllAttributes(globalModelMap); + } + ////////////////////////////// // LIST PAGE @RequestMapping( @@ -51,10 +74,6 @@ public class BookController { dataModel.addAttribute("books", bookRepository.findAll()); - dataModel.addAttribute("deletepage", bookDeletePageView); - dataModel.addAttribute("editpage", bookEditPageView); - dataModel.addAttribute("addpage", bookAddPageView); - httpServerLogger.logMessageNormal( requestData, bookListPageView + ": " + "HTTPOK" @@ -80,9 +99,6 @@ public class BookController { dataModel.addAttribute("book", new Book()); dataModel.addAttribute("categories", categoryRepository.findAll()); - dataModel.addAttribute("addpage", bookAddPageView); - dataModel.addAttribute("listpage", bookListPageView); - if (newBook.getYear() == 0) { newBook.setYear(Year.now().getValue()); } @@ -160,8 +176,6 @@ public class BookController { dataModel.addAttribute("book", book); dataModel.addAttribute("categories", categoryRepository.findAll()); - dataModel.addAttribute("listpage", bookListPageView); - httpServerLogger.logMessageNormal( requestData, bookEditPageView + ": " + "HTTPOK" diff --git a/bookstore/src/main/resources/templates/bookadd.html b/bookstore/src/main/resources/templates/bookadd.html index 1e8bd30..fee13cd 100644 --- a/bookstore/src/main/resources/templates/bookadd.html +++ b/bookstore/src/main/resources/templates/bookadd.html @@ -39,7 +39,7 @@
-
+
diff --git a/bookstore/src/main/resources/templates/bookedit.html b/bookstore/src/main/resources/templates/bookedit.html index 4149013..7f6243e 100644 --- a/bookstore/src/main/resources/templates/bookedit.html +++ b/bookstore/src/main/resources/templates/bookedit.html @@ -39,7 +39,7 @@
-
+
diff --git a/bookstore/src/main/resources/templates/booklist.html b/bookstore/src/main/resources/templates/booklist.html index 2418d58..e52db44 100644 --- a/bookstore/src/main/resources/templates/booklist.html +++ b/bookstore/src/main/resources/templates/booklist.html @@ -26,7 +26,7 @@ - + Delete @@ -35,7 +35,7 @@
- Add Book + Add Book