"How to" control Action Button

After click once, I need to modify action attribute of Create button in visible = “false”. How can I do that?

<actions>
    <action id="create"
            openType="DIALOG"
            visible="false" />
    <action id="edit"
            openType="DIALOG"/>
    <action id="remove"/>
</actions>

Hi,

You can inject Create action and add a BeforeActionPerformedHandler, for instance:

@Named("productsTable.create")
private CreateAction productsTableCreate;

@Override
public void init(Map<String, Object> params) {
    productsTableCreate.setBeforeActionPerformedHandler(() -> {
        productsTableCreate.setVisible(false);
        return true;
    });
}

Regards,
Gleb

It works. Thank you.
The problem is after SAVE the button is visible again.

I tried with setEnable / isEnable but I have only two option: disable forever or enable forever.

Actually I want to perform Create action only once, after that the button should be disabled (invisible) forever.

Well, if you want to create a particular entity only once, then you can check the existence of such entity and enable the create action if no entity has been created.

Below the answer:

@Named(“invoiceTable.create”)
private CreateAction invoiceTableCreate;

private boolean hasNoInvoice()
{
    return getItem() == null || getItem().getInvoice() == null || getItem().getInvoice().size() == 0;
}

@Override
public void init(Map<String, Object> params) {

    boolean ok = hasNoInvoice();
    invoiceTableCreate.setVisible( ok );

//
invoiceTableCreate.setBeforeActionPerformedHandler(() -> {
boolean ok1 = hasNoInvoice();
invoiceTableCreate.setVisible( ok1 );
return ok1;

    });
    //    super.init(params);


}

}

Dear Gleb,

Can you help me please with this topic: How to debug in Idea - CUBA.Platform

Unfortunately I don’t know how to debug in Idea…