Skip to content

Commit dced5df

Browse files
committed
/seres/{id}: do redirect after adding image to prevent multiple form submission.
Fix #139
1 parent 9a3a254 commit dced5df

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public final class Url {
4949

5050
public static final String ADD_SERIES_PAGE = "/series/add";
5151
public static final String INFO_SERIES_PAGE = "/series/{id}";
52+
public static final String ADD_IMAGE_SERIES_PAGE = "/series/{id}/image";
5253

5354
public static final String ADD_CATEGORY_PAGE = "/category/add";
5455
public static final String INFO_CATEGORY_PAGE = "/category/{id}/{slug}";
@@ -97,6 +98,7 @@ public static Map<String, String> asMap(boolean serveContentFromSingleHost) {
9798
map.put("REGISTRATION_PAGE", REGISTRATION_PAGE);
9899
map.put("ADD_SERIES_PAGE", ADD_SERIES_PAGE);
99100
map.put("INFO_SERIES_PAGE", INFO_SERIES_PAGE);
101+
map.put("ADD_IMAGE_SERIES_PAGE", ADD_IMAGE_SERIES_PAGE);
100102
map.put("ADD_CATEGORY_PAGE", ADD_CATEGORY_PAGE);
101103
map.put("INFO_CATEGORY_PAGE", INFO_CATEGORY_PAGE);
102104
map.put("ADD_COUNTRY_PAGE", ADD_COUNTRY_PAGE);

src/main/java/ru/mystamps/web/controller/SeriesController.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public String showInfo(@PathVariable("id") Series series, Model model, User curr
167167
return "series/info";
168168
}
169169

170-
@RequestMapping(value = Url.INFO_SERIES_PAGE, method = RequestMethod.POST)
170+
@RequestMapping(value = Url.ADD_IMAGE_SERIES_PAGE, method = RequestMethod.POST)
171171
public String processImage(
172172
@Validated({ Default.class, AddImageForm.ImageChecks.class }) AddImageForm form,
173173
BindingResult result,
@@ -198,7 +198,11 @@ public String processImage(
198198

199199
seriesService.addImageToSeries(form, series, currentUser);
200200

201-
return "series/info";
201+
String dstUrl = UriComponentsBuilder.fromUriString(Url.INFO_SERIES_PAGE)
202+
.buildAndExpand(series.getId())
203+
.toString();
204+
205+
return "redirect:" + dstUrl;
202206
}
203207

204208
@RequestMapping(

src/main/webapp/WEB-INF/views/series/info.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
<div class="col-sm-4">
256256
<div class="row">
257257
<div class="col-sm-6 col-sm-offset-3">
258-
<form method="post" class="form-horizontal" enctype="multipart/form-data" th:action="@{${INFO_SERIES_PAGE}(id=${series.id})} + '?' + ${_csrf.parameterName} + '=' + ${_csrf.token}" th:object="${addImageForm}">
258+
<form method="post" class="form-horizontal" enctype="multipart/form-data" th:action="@{${ADD_IMAGE_SERIES_PAGE}(id=${series.id})} + '?' + ${_csrf.parameterName} + '=' + ${_csrf.token}" th:object="${addImageForm}">
259259
<div class="form-group" th:classappend="${#fields.hasErrors('image') ? 'has-error' : ''}">
260260
<input type="file" id="image" class="form-control" style="box-shadow: none; border: 0px;" required="required" accept="image/png,image/jpeg" th:field="*{image}" />
261261
<span id="image.errors" class="help-block" th:if="${#fields.hasErrors('image')}" th:each="error : ${#fields.errors('image')}" th:text="${error}"></span>

0 commit comments

Comments
 (0)