TableRemoveEnabledRule is thrown in edit action

Hi, forum followers

On a screen controller class there are coded following rules:

    @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;
    }

When user presses edit button, first the “TableEditEnabledRule” is thrown and afterwards the “TableRemoveEnabledRule” is thrown too and this last rule would act when user presses delete button.

Is it an anomalous behaviour or didn’t I understand well the how does it work?

Regards,

Hi, forum followers.

Finally, I understood how does enabledRule handler works and why all those rules are thrown every time the record is selected on the table.

In my case, first time the record is selected the condition to edit the item is accomplished and the framework lets to edit the record but, when a particular attribute of the item was updated, the condition isn’t accomplished and then notifications that the edition of this record is disabled are shown to user, with the corresponding misunderstood.

For later readers of this post which could need information about enabledRule handler, I let you the reference to Developer’s Manual:
https://doc.cuba-platform.com/manual-7.2/standard_actions.html

Regards,

Xavier

2 Likes