Use enabledRule handler for action in PopupButton?

Hi all,

I have been using the enabledRule handler for actions successfully in the past but now I have created a PopupButton with three action, created enabledRule handlers for each of them but the debugger tells me the rule is never evaluated. Does it not work for PopupButtons?

<buttonsPanel>
     <popupButton id="createAnimal" icon="PLUS">
             <actions>
                   <action id="createCat" type="create" />
                   <action id="createDog" type="create" />
             </actions>
     </popupButton>
</buttonsPanel>

...

@Install(to = "createAnimal.createDog", subject = "enabledRule")
    private boolean createAnimalCreateDogEnabledRule()
    {
        return isAnimalCreatePermitted(metadata.getClass(Dog.class));
    }

Thanks for any hints!

You must refresh actions state.
For instance on popup
myPopupButton.getActions().forEach(Action::refreshState);

Thanks Oleg,
that is very usefull. For normal actions, the refreshing/enabledRule evaluation seems to happen automatically so I was wondering why that is. But your idea is a good workaround.

so I tried it but it does not work. refreshState() exits immediately because target is null. So I suspect it will only work for actions that are bound to a table?

You can inject actions to the screen controller and set their enabled state with setters:

    @Named("testPopupBtn.action1")
    private BaseAction testPopupBtnAction1;

    @Named("testPopupBtn.action2")
    private BaseAction testPopupBtnAction2;

    @Subscribe
    public void onBeforeShow(final BeforeShowEvent event) {
        testPopupBtnAction1.setEnabled(true);
        testPopupBtnAction2.setEnabled(false);
    }

Thanks, that solution is working well now. :slight_smile: