#42 method hasErrors didn't work, return to the previous state
This commit is contained in:
parent
e2e10477ac
commit
51c755ac07
@ -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.GRANTS_PAGE;
|
||||||
import static ru.ulstu.grant.controller.Navigation.GRANT_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.REDIRECT_TO;
|
||||||
import static ru.ulstu.grant.controller.Navigation.hasErrors;
|
|
||||||
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@ -64,10 +63,12 @@ public class GrantController {
|
|||||||
if (grantDto.getDeadlines().isEmpty()) {
|
if (grantDto.getDeadlines().isEmpty()) {
|
||||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
|
||||||
}
|
}
|
||||||
// if (grantDto.getLeader().getId().equals(null)) {
|
if (grantDto.getLeaderId().equals(null)) {
|
||||||
// errors.rejectValue("leader", "errorCode", "Укажите руководителя");
|
errors.rejectValue("leader", "errorCode", "Укажите руководителя");
|
||||||
// }
|
}
|
||||||
hasErrors(errors, GRANT_PAGE);
|
if (errors.hasErrors()) {
|
||||||
|
return GRANT_PAGE;
|
||||||
|
}
|
||||||
grantService.save(grantDto);
|
grantService.save(grantDto);
|
||||||
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
||||||
}
|
}
|
||||||
@ -75,14 +76,18 @@ public class GrantController {
|
|||||||
@PostMapping(value = "/grant", params = "addDeadline")
|
@PostMapping(value = "/grant", params = "addDeadline")
|
||||||
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
||||||
filterEmptyDeadlines(grantDto);
|
filterEmptyDeadlines(grantDto);
|
||||||
hasErrors(errors, GRANT_PAGE);
|
if (errors.hasErrors()) {
|
||||||
|
return GRANT_PAGE;
|
||||||
|
}
|
||||||
grantDto.getDeadlines().add(new Deadline());
|
grantDto.getDeadlines().add(new Deadline());
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/grant", params = "createProject")
|
@PostMapping(value = "/grant", params = "createProject")
|
||||||
public String createProject(@Valid GrantDto grantDto, Errors errors) {
|
public String createProject(@Valid GrantDto grantDto, Errors errors) {
|
||||||
hasErrors(errors, GRANT_PAGE);
|
if (errors.hasErrors()) {
|
||||||
|
return GRANT_PAGE;
|
||||||
|
}
|
||||||
grantService.createProject(grantDto);
|
grantService.createProject(grantDto);
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,7 @@
|
|||||||
package ru.ulstu.grant.controller;
|
package ru.ulstu.grant.controller;
|
||||||
|
|
||||||
import org.springframework.validation.Errors;
|
|
||||||
|
|
||||||
public class Navigation {
|
public class Navigation {
|
||||||
public static final String REDIRECT_TO = "redirect:%s";
|
public static final String REDIRECT_TO = "redirect:%s";
|
||||||
public static final String GRANTS_PAGE = "/grants/grants";
|
public static final String GRANTS_PAGE = "/grants/grants";
|
||||||
public static final String GRANT_PAGE = "/grants/grant";
|
public static final String GRANT_PAGE = "/grants/grant";
|
||||||
|
|
||||||
public static String hasErrors(Errors errors, String page) {
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user