Author Topic: how to update grid recIndx in response after database insert.  (Read 1744 times)

mohta.kam

  • Newbie
  • *
  • Posts: 2
    • View Profile
how to update grid recIndx in response after database insert.
« on: October 27, 2020, 10:17:01 pm »
When I create a new record in the grid it does not have a productid.  My database insert statement creates and returns it.  How do I update the grid with that productid?

Note: I do not want to refresh the entire grid - only the new record. i have checked the batch editing example but failed to understand in below code how dlist is gets the productid  before returning the response.

    @RequestMapping(value="/products/batch", method=RequestMethod.POST)
    public @ResponseBody String batch(@RequestParam String list, HttpServletRequest request ){       
        HttpSession ses = fillInSession(request);
       
        Map dlist = deserializeMap(list);
       
        ArrayList updateList = (ArrayList)dlist.get("updateList");
        ArrayList addList = (ArrayList)dlist.get("addList");
        ArrayList deleteList = (ArrayList)dlist.get("deleteList");
       
        this.updateList(updateList, ses);
        this.addList(addList, ses);
        this.deleteList(deleteList, ses);       
       
        return serializeMap(dlist);
    }


Please help.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: how to update grid recIndx in response after database insert.
« Reply #1 on: October 30, 2020, 09:31:41 am »
New ProductID is set in the addList method.

Code: [Select]
public void addList(ArrayList addList, HttpSession ses ){           

        List<Product> products = (List<Product>)ses.getAttribute("Products");
        int max = getMaxProductID(products);
       
        for (int i = 0; i < addList.size(); i++)
        {
            Product addProduct = (Product)addList.get(i);
            addProduct.setProductID(max+1+i);
            products.add(addProduct);
        }         
    }   

mohta.kam

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: how to update grid recIndx in response after database insert.
« Reply #2 on: October 30, 2020, 11:45:10 am »
But products  object is neither returned and neither used.