java - How to submit a list of checkmark values into a form in Thymeleaf? -


i trying create table displays list of logs have been added. in addition displaying info wanted have column of checkboxes when clicked allow me delete them corresponding delete button.

the issue having unable put values checkboxes array of longs. want keep functionality of table displays correctly.

for table have following code:

<form method="post" th:action="@{/projects/log/delete/}" th:object="${deleteform}">   <div th:each="log : ${alllogs}" class="row">     <tbody>       <tr class="active">         <td>           <input type="checkbox" th:field="*{logids}" th:value="${log.id}" />         </td>         <td th:text="${log.teamused}"></td>         <td th:text="${log.opponentstarters}"></td>         <td th:text="${log.opponentothers}"></td>         <td th:text="${log.mystarters}"></td>         <td th:text="${log.myothers}"></td>         <td th:text="${log.result}"></td>       </tr>     </tbody>   </div>   <button type="submit" id="deletebutton" class="hidden"></button> </form> 

the form trying place checkbox values is: (log.id long)

public class logdeleteform {      private list<long> logids = new arraylist<>();      public list<long> getlogids() {         return logids;     }      public void setlogids(list<long> logids) {         this.logids = logids;     } } 

in controller have following setup view:

@requestmapping(value = "pokemon_log", method = requestmethod.get) public string view(model model) {     model.addattribute("addform", new logform());     model.addattribute("deleteform", new logdeleteform());     model.addattribute("alllogs", logservice.getalllogs());     return "log"; } 

i able implement deletion fine unable ids delete. how can checkbox values placed list of longs?

turns out issue in deletelogs method:

@requestmapping(value = "/log/delete", method = requestmethod.post, params = "delete") public string deletelogs(@modelattribute("deleteform") logdeleteform deleteform) {     list<long> formids = deleteform.getlogids();     if (formids == null || formids.size() == 0) {         return "redirect:/projects/log";     }     (long id : formids) {         logservice.deletelog(id);     }     return "redirect:/projects/log"; } 

my redirects both "redirect:/log" instead of "redirect:/projects/log"

also button missing name="delete" because unable qualify submit delete param.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -