enabledRule handler is triggered a lot of times

Hi, forum followers

An screen controller class implements following ‘enabledRule’ handlers, for disabling edit and remove standard actions in a table depending on the situation:

@Install(to = "ubicacionsTable.edit", subject = "enabledRule")
    private boolean ubicacionsTableEditEnabledRule(){
        boolean swEditar;
        MovimentUbicacio movimentUbicacio = ubicacionsTable.getSingleSelected();
        Ubicacio ubicacio = movimentUbicacio.getUbicacio();
        //Comprovació si aquesta instància de MovimentUbicacio està gravada a la BBDD:
        MovimentUbicacio movubiBD = movimentUbicacioService.tornaRegistre(movimentUbicacio.getUuid());
        //Si no està gravat a la BD no cal comprovar el darrer moviment en la ubicació, perquè vol dir que estàs editant un registre del qual encara no s'ha fet el commit.
        if (movubiBD == null){
            swEditar = true;
        } else {
            swEditar = ubicacioService.esDarrerMoviment(ubicacio, movimentUbicacio);
            if (!swEditar){
                //La ubicació té com a darrer moviment una altra instància de MovimentUbicacio diferent a la que volem editar. No permetre l'edició
                notifications.create(Notifications.NotificationType.ERROR).withCaption("No es permet editar el moviment d'aquesta ubicació perqué s'hi ha fet algun moviment posterior").show();
            }
        }
        return swEditar;
    }

    @Install(to = "ubicacionsTable.remove", subject = "enabledRule")
    private boolean ubicacionsTableRemoveEnabledRule(){
        boolean swEditar;
        MovimentUbicacio movimentUbicacio = ubicacionsTable.getSingleSelected();
        Ubicacio ubicacio = movimentUbicacio.getUbicacio();
        //Comprovació si aquesta instància de MovimentUbicacio està gravada a la BBDD:
        MovimentUbicacio movubiBD = movimentUbicacioService.tornaRegistre(movimentUbicacio.getUuid());
        //Si no està gravat a la BD no cal comprovar el darrer moviment en la ubicació, perquè vol dir que estàs editant un registre que encara no s'ha fet el commit.
        if (movubiBD == null){
            swEditar = true;
        } else {
            swEditar = ubicacioService.esDarrerMoviment(ubicacio, movimentUbicacio);
            if (!swEditar) {
                //La ubicació té com a darrer moviment una altra instància de MovimentUbicacio diferent a la que volem editar. No permetre l'edició
                notifications.create(Notifications.NotificationType.ERROR).withCaption("No es permet eliminar el moviment d'aquesta ubicació perqué s'hi ha fet algun moviment posterior").show();
            }
        }
        return swEditar;
    }

Those handlers include a notification message to inform the user why the action is disabled.
I notice that those handlers are triggered 3 times when item is selected and 8 times when all the transaction is commited, like you can see on the following video:

Is it normal this behaviour? Is there any solution to avoid multiple notifications?

Regards,

Xavier.

Hi,
“enabledRule” methods should contain functional logic determining, whether this action should be enabled or not depending on rows selected in the table.
These rules are calculated every time table selection changes for every action.
You should not show notifications from this method.

If you want the edit action to stay available all the time, but show notification if user clicks the button if hte action is not permitted - then you need to override the whole action’s logic by generating ActionPerformedEvent event handler.

1 Like