多个选择选项值添加到“对象”列表-Thymeleaf

时间:2019-03-09 19:47:41

标签: java html spring thymeleaf

基本上,我有多个select语句,并且我希望能够在每个语句中选择不同的选项,这些选项在提交后将所有选择的选项添加到对象的列表中。以下是我想出的用于执行此操作的代码,但似乎无法正常工作。没有错误,但是对象没有使用不同的值填充列表。如果有人可以帮忙,那就太好了->请参阅下面的代码,以及实际网站的外观图片。

<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="base :: head('project_collaborators')"></head>
<body>
    <header th:replace="base :: header"></header>
    <nav>
        <ul>
            <li class="selected"><a th:href="@{/projects}">Projects</a></li>
            <li><a th:href="@{/collaborators}">Collaborators</a></li>
            <li><a th:href="@{/roles}">Roles</a></li>
        </ul>
    </nav>
    <section>
        <div class="container wrapper">
            <form th:action="@{${action}}" th:method="post" th:object="${project}">
                <input type="hidden" th:field="*{desc}">
                <input type="hidden" th:field="*{status}">
                <input type="hidden" th:field="*{name}">
                <li th:each="role : *{rolesNeeded}" style="display: none">
                    <input type="checkbox" th:field="*{rolesNeeded}" th:value="${role.id}" checked>
                </li>
                <label th:text="${'Edit Collaborators: ' + project.name}">Edit Collaborators: Website Project</label>
                <ul class="checkbox-list">
                    <li th:each="element : ${roleToC}"><span class="primary" th:text="${element.key.name}">Developer</span>
                        <div class="custom-select">
                            <span class="dropdown-arrow"></span>
                            <select th:field="*{collaborators}">
                                <option th:each="c : ${allCollaborators}" th:if="${#strings.equals(c.role.name, element.key.name)}" th:value="${c.id}" th:text="${c.name}" >Michael Pemulis</option>
                            </select>
                        </div>
                    </li>
                </ul>
                <div class="actions">
                    <input type="submit" value="Save" class="button">
                    <a th:href="@{/projects}" class="button button-secondary">Cancel</a>
                </div>
            </form>
        </div>
    </section>
</body>

Live image of code above

0 个答案:

没有答案