Измененное значение формы не отображается при возврате. Есть ли проблема связывания между Thymeleaf и Spring Boot? - PullRequest
0 голосов
/ 20 января 2020

Посмотрите на этот фрагмент листа тимелина в виде:

<form id="onlineRegistrationForm" action="#"
       th:action="@{/__${someId}__/registration}" th:object="${onlineRegistrationForm}"
       method="post" novalidate class="needs-custom-validation">
     ...
    <div class="form-group">
         <label th:for="__${personInstance}__.city" th:text="#{label.city}">city</label>
         <input type="text" class="form-control basicAutoComplete"
                th:id="__${personInstance}__.city"
                aria-describedby="cityHelp" autocomplete="off"
                th:placeholder="#{label.city.ph}"
                th:field="*{__${personInstance}__.city}"
                th:attr="data-noresults-text='__#{search.nf}__'"
                th:attrappend="data-url='/__${someId}__/city/like'"
                th:errorclass="is-invalid">
         <small id="cityHelp" class="form-text text-muted"
                th:unless="${#fields.hasErrors('__${personInstance}__.city')}"
                th:text="#{label.city.tt}">city</small>
         <small id="cityError" class="invalid-feedback"
                th:if="${#fields.hasErrors('__${personInstance}__.city')}"
                th:errors="*{__${personInstance}__.city}">Errors</small>
     </div>

Рассмотрите этот POST - со страницы листа тимьяна:

    @PostMapping(value = "/{someId}/apply")
        public String submitRegistration(@Valid @ModelAttribute(name = "onlineRegistrationForm") OnlineRegistrationForm onlineRegistrationForm,
                                         BindingResult bindingResult,
                                         @PathVariable String someId,
                                         Model model,
                                         RedirectAttributes redirectAttributes)
                throws OnlineRegistrationRuntimeException {
   ...    
            validateOnlineRegistration(s, onlineRegistrationForm, bindingResult);
   ...
                if (bindingResult.hasErrors()) {
                bindingResult.addError(new ObjectError("onlineRegistrationForm", messageSource.getMessage("error.message", new Object[]{""}, LocaleContextHolder.getLocale())));
                return "apply";
            }
   ...

В пределах validateOnlineRegistration я изменяю какое-то поле, скажем city - потому что я определил это по почтовому индексу. Я отследил это изменение до ответного сообщения. Это там.

Я имею в виду, что наличие BindingResult непосредственно после @Valid@Modelattribute, пружины дает мне контроль над @Controller, так почему, черт возьми, изменение не отображается на странице результатов?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...