mercredi 18 novembre 2015

Spring form checkboxes from a list don't appear when all false

I'm insterting a List into form to represent checkboxes. Unfortunately if the list is for example [false, false, false] the checkboxes do not appear in the form. Data is taken from a database so I manualy insterted one true into database. And the checkboxes apear as they should. Any Idea how to make them visible even if all are false ?

My code below:

<form:form method="POST" modelAttribute="characterFunctionWrapper">
        <table>

            <tr>
                <c:forEach items="${characterFunctionWrapper.functionAssigned}" var="assignment" varStatus="loop">
                    <td><form:checkbox path="functionAssigned[${loop.index}]"
                            value="assignment[${loop.index}]" /></td>
                </c:forEach>
            </tr>
            <tr>
                <td colspan="3"><c:choose>
                        <c:when test="${edit}">
                            <input type="submit" value="Update" />
                        </c:when>
                        <c:otherwise>
                            <input type="submit" value="Register" />
                        </c:otherwise>
                    </c:choose></td>
            </tr>
        </table>
    </form:form>

Controller:

@RequestMapping(value = { "/character-{cId}-assignFunction" }, method = RequestMethod.GET)
public String assignFunctionToCharacterForm(@ModelAttribute("characterFunctionWrapper") CharacterFunctionWrapper characterFunctionWrapper,
        @PathVariable int cId, ModelMap model) {
    List<Boolean> functionAssigned = characterFunctionWrapper.getFunctionAssigned();
    List<Function> functionList = characterFunctionWrapper.getFunctionList();

...some logic to insert right values to the list...

    return "characterfunctionassign";
}

Model:

@Entity
public class CharacterFunctionWrapper {

private List<Function> functionList = new ArrayList<Function>();
private List<Boolean> functionAssigned = new ArrayList<Boolean>();
private Character character;
private Function function;




Aucun commentaire:

Enregistrer un commentaire