java - How to implement edit functionality in ThymeLeaf in Spring MVC -
i using this tutorial see delete functionality each row:
7.6 dynamic fields
thanks advanced form-field binding capabilities in spring mvc, can use complex spring el expressions bind dynamic form fields our form-backing bean. allow create new row objects in our seedstarter bean, , add rows’ fields our form @ user request.
in order this, need couple of new mapped methods in our controller, add or remove row our seedstarter depending on existence of specific request parameters:
@requestmapping(value="/seedstartermng", params={"addrow"}) public string addrow(final seedstarter seedstarter, final bindingresult bindingresult) { seedstarter.getrows().add(new row()); return "seedstartermng"; } @requestmapping(value="/seedstartermng", params={"removerow"}) public string removerow( final seedstarter seedstarter, final bindingresult bindingresult, final httpservletrequest req) { final integer rowid = integer.valueof(req.getparameter("removerow")); seedstarter.getrows().remove(rowid.intvalue()); return "seedstartermng"; }
and can add dynamic table our form:
<table> <thead> <tr> <th th:text="#{seedstarter.rows.head.rownum}">row</th> <th th:text="#{seedstarter.rows.head.variety}">variety</th> <th th:text="#{seedstarter.rows.head.seedspercell}">seeds per cell</th> <th> <button type="submit" name="addrow" th:text="#{seedstarter.row.add}">add row</button> </th> </tr> </thead> <tbody> <tr th:each="row,rowstat : *{rows}"> <td th:text="${rowstat.count}">1</td> <td> <select th:field="*{rows[__${rowstat.index}__].variety}"> <option th:each="var : ${allvarieties}" th:value="${var.id}" th:text="${var.name}">thymus thymi</option> </select> </td> <td> <input type="text" th:field="*{rows[__${rowstat.index}__].seedspercell}" /> </td> <td> <button type="submit" name="removerow" th:value="${rowstat.index}" th:text="#{seedstarter.row.remove}">remove row</button> </td> </tr> </tbody> </table>
quite lot of things see here, not should not understand now… except 1 strange thing:
now won't implement edit functionality.
ideas?
Comments
Post a Comment