"Before action" listener for Table standard actions

Hi,

I want to add some validation for the standard table actions, for example, when the entity’s Status attribute of the current table row is “Paid”, then display a message and dis-allow the Edit/Remove actions.

I couldn’t find any “before action” listener for standard actions.

Is custom action the only way?

Hi David,
In order to disable an action depending on some conditions, use the addEnabledRule() method defined in the BaseAction class.

Another option is to override isApplicable() method. You don’t need to create custom actions, just create a subclass of a standard action.
See an example in the platform code.

Thanks for your help and advice Konstantin.

Much appreciate it and will try it out.

Hi Konstantin,

Hope you are doing well.

I have tested addEnabledRule() and the standard actions are enabled/disabled correctly according to the conditional rule(s).

While it’s somewhat workable, i needed a different approach together with some messaging involved. (I can’t add a message in addEnabledRule() as it will be displayed each time a row is selected.)

The behaviour required is like this :

  • Create button - Always enabled, no condition.
  • Edit button - When clicked, do not allow if some condition is met, e.g. item Status is "Paid". Display a message "Transaction cannot be edited as payment is made".
  • Remove button - When clicked, do not allow if some condition is met, e.g. item Status is "Paid". Display a message "Transaction cannot be removed as payment is made".

I tried to find a way to do it but could not figure it out, i.e. i need a way to intercept the action processing.

Just had another go with it.
I think i got it to work as i wanted by overwriting actionPerform() and intercepting the action inside the method.

Thanks.

Hi David,
Perhaps it’s the best way if you want to show a notification instead of disabling the action.
I think we should add a BeforeActionPerformedHandler to simplify this task. Thanks for the hint!

2 Likes