Skip to content

Checkbox object binding form fails on Spring Boot 2.3.1.RELEASE #22508

@Niall7459

Description

@Niall7459

Hi All

First of all I hope this is the correct repository to post this issue, it may be more suitable for the spring-framework repository.

I was having issues with automatic form object binding, however this issue is only occurring on Spring Boot 2.3.1-RELEASE. Discovered the issue after noticing the same technique worked fine on another project under Spring Boot 2.3.0-RELEASE.

class VersionPublishForm {
    Platform[] platforms; //expected to be mapped when the form is submitted
}

However the following exception is thrown:

Failed to convert property value of type java.lang.String[] to required type at.helpch.ecloud.platform.Platform[] for property platforms;
nested exception is java.lang.IllegalStateException: Cannot convert value of type java.lang.String to required type at.helpch.ecloud.platform.Platform for property platforms[0]:
no matching editors or conversion strategy found

As soon as I downgraded the version to 2.3.0-RELEASE. All worked as expected.

If required, heres also the corresponding section of the Thymeleaf template that handles this:

<div class="field">
    <label class="label">Supported Platforms</label>

    <article th:if="${#fields.hasErrors('platforms')}" class="message is-danger">
         <div th:errors="*{platforms}" class="message-body"></div>
    </article>

    <div th:each="platform : ${platformList}">
        <label class="checkbox">
            <input th:field="*{platforms}" th:value="${platform.id}" type="checkbox"/>
            <span th:text="${platform.name}"></span>
        </label>
    </div>
</div>

Another thing to note: The form enctype is multipart/form-data

I have an image here which shows the errors of the BindingResult.

Screen Shot 2020-07-22 at 11 28 26

It seems as if the value "2" (platform id) is being treated as a string, where it should be an integer.

Many Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions