#64 dont show error message

This commit is contained in:
Nightblade73 2019-04-23 13:37:56 +04:00
parent 53cc777734
commit 6d6ea3136d
5 changed files with 41 additions and 12 deletions

View File

@ -68,7 +68,15 @@ public class ConferenceController {
}
@PostMapping(value = "/conferences", params = "deleteConference")
public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException {
public String delete(@Valid ConferenceFilterDto conferenceFilterDto,
@RequestParam("deleteConference") Integer conferenceId,
Errors errors,
ModelMap modelMap) throws IOException {
if (true) {
errors.reject("relationExist", "Статья прикреплена к конференции");
filterConferences(conferenceFilterDto, modelMap);
return CONFERENCES_PAGE;
}
conferenceService.delete(conferenceId);
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
}

View File

@ -11,14 +11,14 @@ public class ConferenceFilterDto {
public ConferenceFilterDto() {
}
public ConferenceFilterDto(List<ConferenceDto> conferenceDtos, Integer filterUserId, Integer year) {
this.conferences = conferenceDtos;
public ConferenceFilterDto(List<ConferenceDto> conferences, Integer filterUserId, Integer year) {
this.conferences = conferences;
this.filterUserId = filterUserId;
this.year = year;
}
public ConferenceFilterDto(List<ConferenceDto> conferenceDtos) {
this(conferenceDtos, null, null);
public ConferenceFilterDto(List<ConferenceDto> conferences) {
this(conferences, null, null);
}
public List<ConferenceDto> getConferences() {

View File

@ -1,5 +1,6 @@
package ru.ulstu.paper.controller;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -95,8 +96,15 @@ public class PaperController {
}
@GetMapping("/delete/{paper-id}")
public String delete(@PathVariable("paper-id") Integer paperId) throws IOException {
paperService.delete(paperId);
public String delete(@Valid PaperFilterDto paperFilterDto,
@PathVariable("paper-id") Integer paperId,
Errors errors) throws IOException {
try {
paperService.delete(paperId);
} catch (DataIntegrityViolationException e) {
errors.reject("relationExist", "Статья прикреплена к конференции");
return "/papers/papers";
}
return "redirect:/papers/papers";
}

View File

@ -8,7 +8,9 @@
<body>
<div layout:fragment="content">
<form id="conferences-form" method="post">
<form id="conferences-form" method="post" th:action="@{'/conferences/conferences'}"
th:object="${filteredConferences}">
<section id="conferences">
<div class="container">
<div class="row" id="conference-list">
@ -18,10 +20,16 @@
</div>
</div>
<hr/>
<div class="alert alert-danger" th:if="${#fields.hasErrors('*')}">
<p th:each="err : ${#fields.errors('*')}" th:text="${err}"></p>
</div>
<div class="row">
<div class="col-md-9 col-sm-12">
<!--<input type="hidden" th:field="${filteredConferences}"/>-->
<th:block th:each="conference : ${filteredConferences.conferences}">
<th:block th:each="conference : *{conferences}">
<div th:replace="conferences/fragments/confLineFragment :: confLine(conference=${conference})"/>
</th:block>
</div>

View File

@ -7,7 +7,8 @@
<body>
<div class="container" layout:fragment="content">
<form id="papers-form" method="post" th:action="@{'/papers/papers'}">
<form id="papers-form" method="post" th:action="@{'/papers/papers'}"
th:object="${filteredPapers}">
<input th:type="hidden" name="paperDeleteId" id="paperDeleteId"/>
<section id="papers">
<div class="container">
@ -17,7 +18,11 @@
<div th:replace="papers/fragments/paperNavigationFragment"/>
</div>
</div>
<div class="row">
<div class="alert alert-danger" th:if="${#fields.hasErrors('*')}">
<p th:each="err : ${#fields.errors('*')}" th:text="${err}"></p>
</div>
<div class="col-md-9 col-sm-12">
<th:block th:each="paper : ${filteredPapers.papers}">
<div th:replace="papers/fragments/paperLineFragment :: paperLine(paper=${paper})"/>
@ -43,7 +48,7 @@
</div>
</div>
</div>
<div th:replace="fragments/noRecordsFragment :: noRecords(entities=${filteredPapers.papers}, noRecordsMessage=' одной статьи', url='paper')"/>
<!--<div th:replace="fragments/noRecordsFragment :: noRecords(entities=${filteredPapers.papers}, noRecordsMessage=' одной статьи', url='paper')"/>-->
</div>
</section>