spring mvc - Validation fails in thymeleaf form but request still goes through -
i'm new thymeleaf (and spring mvc actually), i've read docs , can't seem figure 1 out.
i have standard form:
<form id="form" th:action="@{/next/page}" action="#" th:object="${form}" method="post">
and inside form have input. use thymeleaf validate input on form submit. validation looks like:
th:if="${#fields.haserrors('something')}" th:errors="*{something}">
my controller has method following signature:
@requestmapping(value = "/next/page", method = requestmethod.post) public string example(@valid form form, bindingresult bindingresult, httpservletrequest request, httpservletresponse response) { if(bindingrequest.haserrors()) { return page-my-form-is-on; } ... other stuff here ... }
when form submitted , there's validation error, seems page still navigating /next/page specified in th:action, when loads, still same page form on validation error message shown.
how can cancel request , prevent navigating /next/page when there's validation error? when there's validation error want stay on same page , display error.
Comments
Post a Comment