Implementing Before Action Performed Handler


I want is such that the removeAction can only work if the paid amount =<0.


Now unfortunately my code below doesn’t work because as long as one of the schedule has been paid, the Datasource will aggregate the paid amounts and they will always be more than 0. How can I enforce it to limit to only the selected line?

private CollectionDatasource<PaymentSchedule, UUID> paymentScheduleDs;
private RemoveAction removeAction;

public void init(Map<String, Object> params) {
    removeAction.setBeforeActionPerformedHandler(new Action.BeforeActionPerformedHandler() {
        public boolean beforeActionPerformed() {
            return paymentScheduleDs.getItems().iterator().next().getPaidAmount() <= 0; // || paymentScheduleDs.getItems().iterator().next().getPaidAmount() == 0;



Thanks in advance.


Hi Kenince!

Actually, in your code the datasource doesn’t aggregate any values, you only check the value from the first row.
I’d advise you to use EnabledRule to enable and disable the action as follows:

// we can use lambda expression instead of anonymous class
removeAction.addEnabledRule(() -> {
    PaymentSchedule item = paymentScheduleDs.getItem(); // get selected item
    return selectedItem != null && selectedItem.getPaidAmount() <= 0;
1 Like