#55 added nav controller
This commit is contained in:
parent
3e5aeaf290
commit
db43da9ec0
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user