From 51c755ac077dce549be9f0bfc7b9ba5fbc86d8d5 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 10 Apr 2019 09:39:07 +0400 Subject: [PATCH] #42 method hasErrors didn't work, return to the previous state --- .../grant/controller/GrantController.java | 19 ++++++++++++------- .../ru/ulstu/grant/controller/Navigation.java | 9 --------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 98ddd70..2928fe2 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -25,7 +25,6 @@ import static org.springframework.util.StringUtils.isEmpty; import static ru.ulstu.grant.controller.Navigation.GRANTS_PAGE; import static ru.ulstu.grant.controller.Navigation.GRANT_PAGE; import static ru.ulstu.grant.controller.Navigation.REDIRECT_TO; -import static ru.ulstu.grant.controller.Navigation.hasErrors; @Controller() @@ -64,10 +63,12 @@ public class GrantController { if (grantDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } -// if (grantDto.getLeader().getId().equals(null)) { -// errors.rejectValue("leader", "errorCode", "Укажите руководителя"); -// } - hasErrors(errors, GRANT_PAGE); + if (grantDto.getLeaderId().equals(null)) { + errors.rejectValue("leader", "errorCode", "Укажите руководителя"); + } + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantService.save(grantDto); return String.format(REDIRECT_TO, GRANTS_PAGE); } @@ -75,14 +76,18 @@ public class GrantController { @PostMapping(value = "/grant", params = "addDeadline") public String addDeadline(@Valid GrantDto grantDto, Errors errors) { filterEmptyDeadlines(grantDto); - hasErrors(errors, GRANT_PAGE); + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantDto.getDeadlines().add(new Deadline()); return GRANT_PAGE; } @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) { - hasErrors(errors, GRANT_PAGE); + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantService.createProject(grantDto); return GRANT_PAGE; } diff --git a/src/main/java/ru/ulstu/grant/controller/Navigation.java b/src/main/java/ru/ulstu/grant/controller/Navigation.java index bf1626f..8ee49bc 100644 --- a/src/main/java/ru/ulstu/grant/controller/Navigation.java +++ b/src/main/java/ru/ulstu/grant/controller/Navigation.java @@ -1,16 +1,7 @@ package ru.ulstu.grant.controller; -import org.springframework.validation.Errors; - public class Navigation { public static final String REDIRECT_TO = "redirect:%s"; public static final String GRANTS_PAGE = "/grants/grants"; public static final String GRANT_PAGE = "/grants/grant"; - - public static String hasErrors(Errors errors, String page) { - if (errors.hasErrors()) { - return page; - } - return null; - } }