Entity Listener Restrict Delete or Update - Best practice


I want to perform some validation in the entity listener to restrict delete or Update.
If a certain condition is true, cancel the update or delete.
I know you can override the table actions in the UI or use the postValidate() in the controller.
But the entities can be changed from multiple screens. I want to make sure it’s validated in a single place.
Entity Listener looks like a good options, but this method returns void.
So the solution I have now is to throw an exception from the entity listener, to stop the operation.

Is there any other way to this in CUBA without throwing an exception from middle ware?
Or is exception throwing the way to go?


Hi Renato,

Throwing an exception in an entity listener is a perfectly valid way to prevent update or deletion. You may also want to use a corresponding exception handler to notify the user.

1 Like