0

In workers.jsp I have:

    ....
    <form action="/workers" id="personForm" method="post" >

    <c:forEach items="${page.content}" var="row" varStatus="status">
    <tr>
    <td><input type="checkbox"/></td>
    <td>${row.name}</td>
                     ...
     <td>
    <input type='image' src='/pages/img/del.png' />
    <input type='hidden' name="removeid" value='${row.id}'/>
    </td>
    </tr>
    </c:forEach>
    </form>

When I click on input, ${row.id} goes to:

   @RequestMapping(value = "/workers", method = RequestMethod.POST)
    public ModelAndView getAllByPage(@ModelAttribute("removeid") Long removeid, Model uiModel, Pageable pageable) {

    if(removeid!=null) {
       userService.remove(removeid);
    }

   ...

   } 

But removeid in this case is always the first, that was added to the jsp page. Besides that, how to get the array of ids, using jsp to remove many items?

Help me, please.

Tom Wally
  • 542
  • 3
  • 8
  • 20

1 Answers1

0

You can write 1 separate REST end point for deleting multiple items. Example:

public List<Long> deleteMultiple(List<Long> toBeDeleted){
    deleteService(toBeDeleted);
    return toBeDeleted;
}

You can call this End point via AJAX with multiple ides & refresh your page.

nazmul19
  • 32
  • 4
  • Thanks! I will use it) But the second part of question is how to gather ids to the List? – Tom Wally May 08 '16 at 18:43
  • the common way of doing it is including a `List` to the Model. It can't be a list of `long` because you need to change the state of the single obj with the checkbox tick. So probably `MyObj` class will have, say, an attribute `id` and an attribute `checked`. So, in the `foreach` statement you will iterate over the list creating a row per obj whose `checked` attribute will be bound to the checkbox item. If you need help in managing lists in jsp, look at [this](http://stackoverflow.com/a/15481311/740480). – MaVVamaldo May 08 '16 at 23:12
  • You can use @RequestParam in your REST End point. Example: public List deleteMultiple(@RequestParam(value = "toBeDeletedIds", required = false, defaultValue = "") Long[] toBeDeletedIds){ deleteService(toBeDeleted); return toBeDeleted; } – nazmul19 May 09 '16 at 05:17