From 4b2f084e286b0c2f3f5da8fa2284e73a98f4c637 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Wed, 24 Oct 2018 17:36:04 +0200 Subject: [PATCH] Use message source in Web UI sample Update the sample application to show how a message source can be used in the view tier. Closes gh-14947 See gh-14882 --- .../spring-boot-sample-web-ui/pom.xml | 4 ++++ .../sample/web/ui/mvc/MessageController.java | 2 +- .../src/main/resources/messages.properties | 21 +++++++++++++++++++ .../main/resources/templates/fragments.html | 4 ++-- .../resources/templates/messages/form.html | 12 +++++------ .../resources/templates/messages/list.html | 14 ++++++------- .../resources/templates/messages/view.html | 12 +++++------ 7 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/messages.properties diff --git a/spring-boot-samples/spring-boot-sample-web-ui/pom.xml b/spring-boot-samples/spring-boot-sample-web-ui/pom.xml index c0b1e4c3ae..db3e01e5ef 100755 --- a/spring-boot-samples/spring-boot-sample-web-ui/pom.xml +++ b/spring-boot-samples/spring-boot-sample-web-ui/pom.xml @@ -24,6 +24,10 @@ org.springframework.boot spring-boot-starter-thymeleaf + + org.springframework.boot + spring-boot-devtools + org.springframework.boot diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java index f66f54df48..fd56444d5a 100755 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/java/sample/web/ui/mvc/MessageController.java @@ -64,7 +64,7 @@ public class MessageController { return new ModelAndView("messages/form", "formErrors", result.getAllErrors()); } message = this.messageRepository.save(message); - redirect.addFlashAttribute("globalMessage", "Successfully created a new message"); + redirect.addFlashAttribute("globalMessage", "view.success"); return new ModelAndView("redirect:/{message.id}", "message.id", message.getId()); } diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/messages.properties b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/messages.properties new file mode 100644 index 0000000000..8741cc2e1e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/messages.properties @@ -0,0 +1,21 @@ +form.message=Message +form.messages=Messages +form.submit=Submit +form.summary=Summary +form.title=Messages : Create + +list.create=Create Message +list.table.created=Created +list.table.empty=No messages +list.table.id=Id +list.table.summary=Summary +list.title=Messages : View all + +navbar.messages=Messages +navbar.thymeleaf=Thymeleaf + +view.delete=delete +view.messages=Messages +view.modify=modify +view.success=Successfully created a new message +view.title=Messages : View diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/fragments.html b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/fragments.html index 0d683155f7..c8dc7affed 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/fragments.html +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/fragments.html @@ -8,9 +8,9 @@ diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/form.html b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/form.html index 1d564bfbae..d016e5f453 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/form.html +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/form.html @@ -1,15 +1,15 @@ - Messages : Create + Messages : Create
-

Messages : Create

+

Messages : Create

- +
- +
- +
diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/list.html b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/list.html index 88f00a8fd2..be8d130d28 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/list.html +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/list.html @@ -1,26 +1,26 @@ - Messages : View all + Messages : View all
-

Messages : View all

+

Messages : View all

- - - + + + - + diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/view.html b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/view.html index e32cb74e03..10eafb609b 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/view.html +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/templates/messages/view.html @@ -1,25 +1,25 @@ - Messages : View + Messages : View
-

Messages : View

+

Messages : View

-
Some Success message +
Some Success message

123 - A short summary...

July 11, 2012 2:17:16 PM CDT

A detailed message that is longer than the summary.

- delete - modify + delete + modify
IDCreatedSummaryIDCreatedSummary
No messagesNo messages
1