Skip to content

Commit 0172e38

Browse files
cssruphp-coder
authored andcommitted
/site/index: add validation for catalog number to fix IllegalArgumentException.
Fix #341
1 parent 38799b6 commit 0172e38

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import javax.servlet.http.HttpServletResponse;
3131
import javax.validation.groups.Default;
3232

33+
import org.apache.commons.lang3.StringUtils;
34+
3335
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
3436
import org.springframework.stereotype.Controller;
3537
import org.springframework.ui.Model;
@@ -345,12 +347,12 @@ public String searchSeriesByCatalog(
345347
@RequestParam("catalogName") String catalogName,
346348
Model model,
347349
Locale userLocale,
348-
HttpServletResponse response)
350+
RedirectAttributes redirectAttributes)
349351
throws IOException {
350352

351-
if (catalogNumber == null) {
352-
response.sendError(HttpServletResponse.SC_NOT_FOUND);
353-
return null;
353+
if (StringUtils.isBlank(catalogNumber)) {
354+
redirectAttributes.addFlashAttribute("numberIsEmpty", true);
355+
return "redirect:" + Url.INDEX_PAGE;
354356
}
355357

356358
String lang = LocaleUtils.getLanguageOrNull(userLocale);

src/main/resources/application-prod.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spring.messages.cache-seconds: -1
2626
spring.messages.fallback-to-system-locale: false
2727
spring.messages.basename: \
2828
ru/mystamps/i18n/Messages, \
29+
ru/mystamps/i18n/ValidationMessages, \
2930
ru/mystamps/i18n/SpringSecurityMessages, \
3031
ru/mystamps/i18n/MailTemplates
3132

src/main/resources/application-test.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ spring.messages.cache-seconds: 60
2828
spring.messages.fallback-to-system-locale: false
2929
spring.messages.basename: \
3030
ru/mystamps/i18n/Messages, \
31+
ru/mystamps/i18n/ValidationMessages, \
3132
ru/mystamps/i18n/SpringSecurityMessages, \
3233
ru/mystamps/i18n/MailTemplates
3334

src/main/resources/application-travis.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spring.messages.cache-seconds: -1
2626
spring.messages.fallback-to-system-locale: false
2727
spring.messages.basename: \
2828
ru/mystamps/i18n/Messages, \
29+
ru/mystamps/i18n/ValidationMessages, \
2930
ru/mystamps/i18n/SpringSecurityMessages, \
3031
ru/mystamps/i18n/MailTemplates
3132

src/main/resources/ru/mystamps/i18n/ValidationMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ value.too-short = Value is less than allowable minimum of {min} characters
2424
value.too-long = Value is greater than allowable maximum of {max} characters
2525
value.invalid-length = Value length must be equals to {max} characters
2626
value.hyphen = Value must not start or end with hyphen
27+
value.empty = Value must not be empty
2728

2829
category-name-en.invalid = Category name must consist only latin letters, hyphen or spaces
2930
category-name-ru.invalid = Category name must consist only Russian letters, hyphen or spaces

src/main/resources/ru/mystamps/i18n/ValidationMessages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ value.too-short = Значение должно быть не менее {min}
2424
value.too-long = Значение должно быть не более {max} символов
2525
value.invalid-length = Значение должно быть длинной {max} символов
2626
value.hyphen = Значение не должно начинаться или заканчиваться знаком дефиса
27+
value.empty = Значение не должно быть пустым
2728

2829
category-name-en.invalid = Название категории может содержать только латинские буквы, дефис или пробел
2930
category-name-ru.invalid = Название категории может содержать только кирилические буквы, дефис или пробел

src/main/webapp/WEB-INF/views/site/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,14 @@ <h4 class="panel-title" th:text="#{t_search_by_catalog}">Search by catalog</h4>
247247
</div>
248248
<div class="panel-body">
249249
<form method="post" action="../series/search_result.html" th:action="@{${SEARCH_SERIES_BY_CATALOG}}">
250-
<div class="form-group">
250+
<div class="form-group" th:classappend="${numberIsEmpty != null ? 'has-error' : ''}">
251251
<label for="catalogNumber" th:text="|#{t_number}:|">Number:</label>
252252
<input id="catalogNumber" name="catalogNumber" type="search" class="form-control" required="required" />
253+
<!--/*/
254+
<span th:if="${numberIsEmpty != null}" th:text="#{value.empty}" class="help-block">
255+
Value must not be empty
256+
</span>
257+
/*/-->
253258
</div>
254259
<div class="form-group">
255260
<label for="catalogName" th:text="|#{t_catalog}:|">Catalog:</label>

0 commit comments

Comments
 (0)