I can't identify the problem - thymeleaf does not populate input field value

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

I can't identify the problem - thymeleaf does not populate input field value

SchlauFuchs
Hi,

This is bothering me now for a few hours. I have a very simple web form, having two input fields. The backend is a spring-boot application. the form object contains two String properties. It barely can get simpler than that.

here a bit of the web form:

<form method="post" th:action="@{/submit}" th:object="${topicForm}">
        <div class="form-group">
            <label th:for="title">Title:</label>
            <input th:field="*{title}" class="form-control" />
            <ul th:if="${#fields.hasErrors('title')}">
                <li class="fieldError" th:each="err : ${#fields.errors('title')}" th:text="${err}">Problems</li>
            </ul>
        </div>
        <div class="form-group">
            <label th:for="description">Description:</label>
            <textarea class="form-control" th:field="*{description}"></textarea>
            <ul th:if="${#fields.hasErrors('description')}">
                <li class="fieldError" th:each="err : ${#fields.errors('description')}" th:text="${err}">Problems</li>
            </ul>
        </div>
        <input class="btn btn-primary" type="submit" value="Submit"/>
        <input class="btn" type="reset" value="Reset"/>
        <ul th:if="${#fields.hasErrors('global')}">
            <li th:each="err : ${#fields.errors('global')}" th:text="${err}">Problems</li>
        </ul>
    </form>

The problem is field title in row 4 here. It renders value as empty string. But it only does so after the form POST returning to the same template again after validation failed. When I populate the form object on the initial GET request, it renders fine. I have debugged the controller in Java, the model object definitely has the field populated before returning it.

Any suggestions?
Reply | Threaded
Open this post in threaded view
|

Re: I can't identify the problem - thymeleaf does not populate input field value

johnsmith101
This post was updated on .
SchlauFuchs wrote
Hi,

This is bothering me now for a few hours. I have a very simple web form, having two input fields. The backend is a spring-boot application. the form object contains two String properties. It barely can get simpler than that.

here a bit of the web form:

<form method="post" th:action="@{/submit}" th:object="${topicForm}">
        <div class="form-group">
            <label th:for="title">Title:</label>
            <input th:field="*{title}" class="form-control" />
            <ul th:if="${#fields.hasErrors('title')}">
                <li class="fieldError" th:each="err : ${#fields.errors('title')}" th:text="${err}">Problems</li>
            </ul>
        </div>
        <div class="form-group">
            <label th:for="description">Description:</label>
            <textarea class="form-control" th:field="*{description}"></textarea>
            <ul th:if="${#fields.hasErrors('description')}">
                <li class="fieldError" th:each="err : ${#fields.errors('description')}" th:text="${err}">Problems</li>
            </ul>
        </div>
        <input class="btn btn-primary" type="submit" value="Submit"/>
        <input class="btn" type="reset" value="Reset"/>
        <ul th:if="${#fields.hasErrors('global')}">
            <li th:each="err : ${#fields.errors('global')}" th:text="${err}">Problems</li>
        </ul>
    </form>

The problem is field title in row 4 here. It renders value as empty string. But it only does so after the form POST returning to the same template again after validation failed. When I populate the form object on the initial GET request, it renders fine. I have debugged the controller in Java, the model object definitely has the field populated before returning it.

Any suggestions?
Hello,

Damm even I am having a similar kind of issue, I have searched all over the

internet and even have posted on number of threads on different forum, no

solution seems to work. I am really frustrated, can anyone of you here help

me resolve this issue, I am very much tired now.

Thanks and regards 9apps app cartoon hd apk