I want to solve the following problem, it’s about deleting entities from a database:
- The user selects Delete for a certain entity
- The is deleted from the database and disappeared from the list
- An undo frame appears inside the page (like Twitter Bootstrap alert messages), where the user can choose to undo the deletion.
I don’t know how to realize this, because at the moment I solve this that way:
- Delete button links to the URL: delete/entity_id
- I have written an if-case for this URL in my request handler that deletes the entity
- after the deletion is done, I send a
response.sendRedirect(/list)so the updated list is shown
This way I cannot send additional data by redirecting it. Normally I would send the extra data by processing them via the template, but with redirect this is not possible.
How is such a sitation solved?
You could use the
setAttribute()andgetAttribute()methods of HttpSession. After all that’s a way how you can pass Java objects over different HTTP requests.In your case you could create such an Undo object and store it in the session. After the redirect you have described the session object is retrieved and its content is passed to the template.