#55 Navigation's method "hasErrors" don't work. it returns String, not redirection.

This commit is contained in:
Nightblade73 2019-04-09 14:47:14 +04:00
parent 689a7799e3
commit c308a5e5af
2 changed files with 9 additions and 4 deletions

View File

@ -22,7 +22,6 @@ import static org.springframework.util.StringUtils.isEmpty;
import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
import static ru.ulstu.core.controller.Navigation.hasErrors;
@Controller()
@ -56,7 +55,8 @@ public class ConferenceController {
if (conferenceDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
}
hasErrors(errors, CONFERENCE_PAGE);
if (errors.hasErrors())
return CONFERENCE_PAGE;
conferenceService.save(conferenceDto);
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
@ -65,7 +65,8 @@ public class ConferenceController {
@PostMapping(value = "/conference", params = "addDeadline")
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
filterEmptyDeadlines(conferenceDto);
hasErrors(errors, CONFERENCE_PAGE);
if (errors.hasErrors())
return CONFERENCE_PAGE;
conferenceDto.getDeadlines().add(new Deadline());
return CONFERENCE_PAGE;
}

View File

@ -30,6 +30,9 @@
<label for="title">Название:</label>
<input class="form-control" th:field="*{title}" id="title" type="text"
placeholder="Название конференции"/>
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
@ -61,11 +64,12 @@
$('#deadlines${rowStat.index}\\.date').val('');
$('#addDeadline').click();|"/>
</div>
</div>
</div>
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p>
<div class="form-group d-flex justify-content-end">
<input type="submit" id="addDeadline" name="addDeadline"