I want to remove the item that is added to the cart. The cart will have the added items, with the delete button against each item.When i click the delete button,
the item is not removed from cart.Cart loads with already added items.How to delete an item.Please help me
Looks like an object equality issue to me. The object obtained from your productService.getProductById(int id) method is not equal to the object in your Shopping List when compared using.equals(), which a List will do during its .remove() operation.
Edit: (Moderator Tim) Moved from Spring forum to Java in General. I don't think this issue has anything to do with Spring.
I would suggest a couple things. First, if you have not already you may need to override the equals() method in your Product class. This will ensure the ArrayList.remove() method is properly determining if the objects are equal.
Second I would output the "id" parameter being passed into the removeFromCart() method on the controller and the Index of the object in the ArrayList to see if they are correct.
Like Tim said, it seems like an equality issue is which case you should have a look at the equals() method in the Product class. If the Product class does not have it's own equals() method, you should add one and override the one inherited from the base Object class.