mardi 1 août 2017

Spring + jQuery + FTL: how to handle checkbox value of "on" or null

When I serialize my form and use some code to turn the serialized query string into a JSON object, the checkboxes I inserted with:

<@spring.formCheckbox path="signUpDto.checkbox_terms" />

have "checked" and "unchecked" values of "on" and null respectively. I googled this behavior, and I found it is standard behavior of jQuery form serialization.

In my DTO, my checkbox_terms variable is declared like this:

private boolean checkbox_terms;

However, when I try to post my serialized object form data back to the server, it returns a 415 error (Unsupported media type). It might be because of this wrong data type on checkbox_terms as the two values are "on" and null.

So my question is, how should I handle this situation?




Aucun commentaire:

Enregistrer un commentaire