#55 added nav controller

This commit is contained in:
Nightblade73 2019-04-07 10:01:44 +04:00
parent 3e5aeaf290
commit db43da9ec0
2 changed files with 25 additions and 4 deletions

View File

@ -18,6 +18,11 @@ import java.io.IOException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.StringUtils.isEmpty; 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() @Controller()
@RequestMapping(value = "/conferences") @RequestMapping(value = "/conferences")
@ -51,11 +56,9 @@ public class ConferenceController {
if (conferenceDto.getDeadlines().isEmpty()) { if (conferenceDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
} }
if (errors.hasErrors()) { hasErrors(errors, CONFERENCE_PAGE);
return "/conferences/conference";
}
conferenceService.save(conferenceDto); conferenceService.save(conferenceDto);
return "redirect:/conferences/conferences"; return String.format(REDIRECT_TO, CONFERENCES_PAGE);
} }

View File

@ -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;
}
}