jeudi 23 février 2017

Setting boolean with th:checked

I have a model which includes a boolean 'deleted'. I generate a list and each element has this variable within it.

I print it out in a list and I'm trying to set it using a checkbox, so it saves whatever is set.

Model

public class entry{
private boolean deleted;

public entry(boolean deleted){
this.deleted = deleted;
}

//setters & getters for deleted
}

I then have my thymeleaf form read in this list using a wrapper class. Which works fine.

I can get the checkbox to display checked/unchecked depending on the deleted state for each element, but it if I change the checkbox from checked to unchecked...it doesn't then save the variable to that state.

HTML

<div th:each="entry, stat: *{entryList}">
  <td>
    <label class="switch"> 
      <input name="index" th:type="checkbox" th:checked="*{entryList[__${stat.index}__].deleted}">
      </input> <span class="delete round">
    </span>
    </label>
 </td>
       </div>




Aucun commentaire:

Enregistrer un commentaire