Browse Source

Generalize web form URL scheme

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.1-alpha
Pekka Helenius 4 years ago
parent
commit
382c8e9136
4 changed files with 27 additions and 13 deletions
  1. +23
    -9
      bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java
  2. +1
    -1
      bookstore/src/main/resources/templates/bookadd.html
  3. +1
    -1
      bookstore/src/main/resources/templates/bookedit.html
  4. +2
    -2
      bookstore/src/main/resources/templates/booklist.html

+ 23
- 9
bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java View File

@ -3,6 +3,8 @@
package com.fjordtek.bookstore.web; package com.fjordtek.bookstore.web;
import java.time.Year; import java.time.Year;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
@ -32,6 +34,20 @@ public class BookController {
private static final String bookDeletePageView = "bookdelete"; private static final String bookDeletePageView = "bookdelete";
private static final String bookEditPageView = "bookedit"; private static final String bookEditPageView = "bookedit";
private static String currency_symbol = "€";
private Map<String,String> globalModelMap = new HashMap<String,String>() {
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 HttpServerLogger httpServerLogger = new HttpServerLogger();
//private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler(); //private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler();
@ -41,6 +57,13 @@ public class BookController {
@Autowired @Autowired
private CategoryRepository categoryRepository; private CategoryRepository categoryRepository;
@ModelAttribute
public void globalAttributes(Model dataModel) {
// Security implications of adding these all?
dataModel.addAllAttributes(globalModelMap);
}
////////////////////////////// //////////////////////////////
// LIST PAGE // LIST PAGE
@RequestMapping( @RequestMapping(
@ -51,10 +74,6 @@ public class BookController {
dataModel.addAttribute("books", bookRepository.findAll()); dataModel.addAttribute("books", bookRepository.findAll());
dataModel.addAttribute("deletepage", bookDeletePageView);
dataModel.addAttribute("editpage", bookEditPageView);
dataModel.addAttribute("addpage", bookAddPageView);
httpServerLogger.logMessageNormal( httpServerLogger.logMessageNormal(
requestData, requestData,
bookListPageView + ": " + "HTTPOK" bookListPageView + ": " + "HTTPOK"
@ -80,9 +99,6 @@ public class BookController {
dataModel.addAttribute("book", new Book()); dataModel.addAttribute("book", new Book());
dataModel.addAttribute("categories", categoryRepository.findAll()); dataModel.addAttribute("categories", categoryRepository.findAll());
dataModel.addAttribute("addpage", bookAddPageView);
dataModel.addAttribute("listpage", bookListPageView);
if (newBook.getYear() == 0) { if (newBook.getYear() == 0) {
newBook.setYear(Year.now().getValue()); newBook.setYear(Year.now().getValue());
} }
@ -160,8 +176,6 @@ public class BookController {
dataModel.addAttribute("book", book); dataModel.addAttribute("book", book);
dataModel.addAttribute("categories", categoryRepository.findAll()); dataModel.addAttribute("categories", categoryRepository.findAll());
dataModel.addAttribute("listpage", bookListPageView);
httpServerLogger.logMessageNormal( httpServerLogger.logMessageNormal(
requestData, requestData,
bookEditPageView + ": " + "HTTPOK" bookEditPageView + ": " + "HTTPOK"


+ 1
- 1
bookstore/src/main/resources/templates/bookadd.html View File

@ -39,7 +39,7 @@
<label for="BookPrice">Price</label> <label for="BookPrice">Price</label>
<div class="input-group mb-2"> <div class="input-group mb-2">
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text"></div>
<div class="input-group-text" th:text="${currency_symbol}"></div>
</div> </div>
<input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/> <input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/>
</div> </div>


+ 1
- 1
bookstore/src/main/resources/templates/bookedit.html View File

@ -39,7 +39,7 @@
<label for="fname">Price</label> <label for="fname">Price</label>
<div class="input-group mb-2"> <div class="input-group mb-2">
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text"></div>
<div class="input-group-text" th:text="${currency_symbol}"></div>
</div> </div>
<input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/> <input class="form-control" type="text" th:field="*{price}" placeholder="Book price"/>
</div> </div>


+ 2
- 2
bookstore/src/main/resources/templates/booklist.html View File

@ -26,7 +26,7 @@
<td th:text="${book.isbn}"></td> <td th:text="${book.isbn}"></td>
<td th:text="${book.year}"></td> <td th:text="${book.year}"></td>
<td th:text="${book.category.getName()}"></td> <td th:text="${book.category.getName()}"></td>
<td th:text="${#numbers.formatDecimal(book.price, 1, 2)}"></td>
<td th:text="${#numbers.formatDecimal(book.price, 1, 2)}+ ' ' + ${currency_symbol}"></td>
<td><a class="btn btn-danger" <td><a class="btn btn-danger"
th:attr="onclick='javascript:return confirm(\'' + 'Delete book: ' + ${book.title} + '?' + '\');'" th:attr="onclick='javascript:return confirm(\'' + 'Delete book: ' + ${book.title} + '?' + '\');'"
th:href="@{__${deletepage}__/{id}(id=${book.id})}">Delete</a></td> th:href="@{__${deletepage}__/{id}(id=${book.id})}">Delete</a></td>
@ -35,7 +35,7 @@
</tr> </tr>
</table> </table>
<div> <div>
<a class="btn btn-success" href="@{__${addpage}__}">Add Book</a>
<a class="btn btn-success" th:href="@{__${addpage}__}">Add Book</a>
</div> </div>
</div> </div>
</body> </body>


Loading…
Cancel
Save