From db43da9ec0e4b5806f65052cbaf2e6221f62b39a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 7 Apr 2019 10:01:44 +0400 Subject: [PATCH] #55 added nav controller --- .../controller/ConferenceController.java | 11 +++++++---- .../controller/NavigationController.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/controller/NavigationController.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index d957e76..c3b4917 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -18,6 +18,11 @@ import java.io.IOException; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; +import static ru.ulstu.conference.controller.NavigationController.CONFERENCES_PAGE; +import static ru.ulstu.conference.controller.NavigationController.CONFERENCE_PAGE; +import static ru.ulstu.conference.controller.NavigationController.REDIRECT_TO; +import static ru.ulstu.grant.controller.Navigation.hasErrors; + @Controller() @RequestMapping(value = "/conferences") @@ -51,11 +56,9 @@ public class ConferenceController { if (conferenceDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } - if (errors.hasErrors()) { - return "/conferences/conference"; - } + hasErrors(errors, CONFERENCE_PAGE); conferenceService.save(conferenceDto); - return "redirect:/conferences/conferences"; + return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/controller/NavigationController.java b/src/main/java/ru/ulstu/conference/controller/NavigationController.java new file mode 100644 index 0000000..84f88ad --- /dev/null +++ b/src/main/java/ru/ulstu/conference/controller/NavigationController.java @@ -0,0 +1,18 @@ +package ru.ulstu.conference.controller; + +import org.springframework.validation.Errors; + +public class NavigationController { + + public static final String REDIRECT_TO = "redirect:%s"; + public static final String CONFERENCES_PAGE = "/conferences/conferences"; + public static final String CONFERENCE_PAGE = "/conferences/conference"; + + public static String hasErrors(Errors errors, String page) { + if (errors.hasErrors()) { + return page; + } + return null; + } + +}