Skip to content

Undo

Status: ✅ Implemented

Confirmation dialogs tax every operation to protect against the rare mistake. The friendlier contract is act immediately, offer a way back: archive the document, show “Documento archivado — Deshacer”, and only the mistaken click costs anything.

Return Message.undoable(...) from the action:

@Button
public Message archive(HttpRequest httpRequest) {
service.archive(docId); // soft-delete: keep the row restorable
return Message.undoable("Documento archivado", "restore", Map.of("docId", docId));
}
@Action // only the toast names it: mark it, or strict action mode refuses it
public Message restore(HttpRequest httpRequest) {
var docId = String.valueOf(httpRequest.runActionRq().parameters().get("docId"));
service.restore(docId);
return Message.success("Documento restaurado");
}
  • The toast shows the text plus an Undo button (label undoLabel; when unset, the renderer’s own word for Undo in the app’s language) and stays 10 seconds by default.
  • Clicking Undo dispatches undoActionId on the initiator component with undoParameters as action parameters — a plain method of the same class that reverses the effect itself.
  • The pattern presumes soft-delete (or an equivalent reversible operation): keep the data, flag it, restore on undo. For truly irreversible operations keep @ListToolbarButton(confirmationRequired = true) instead — undo and confirmation are complementary, not exclusive.
  • Works after bulk actions too: pass the affected ids in undoParameters and restore them all.

Oracle’s oj-sp-messages-toast carries no actions, so an undoable message is shown with JET’s own notification — an oj-messages (display notification) whose oj-message puts the Undo oj-button in its detail slot, the slot JET reserves for links and buttons. Pressing it runs the undo action on the page that produced the message and closes the notification. Demo: moving or resizing a stay on the Room Diary of demo-vb-pms.