Set component enabled/disabled programmatically in edit mode

I want to set enabled/disabled some lookup components if a checkbox is checked or not. And refresh if checkbox state changes. Thanks in advance for any help.

Hi Apunzi
You can inject the component in the controller and disable it like mycomp.setEnable(false).

Mortoza

Thanks for your answer. I know how to use a listener to refresh enabled/disabled states when checkbox is clicked. My problem is, I can’t remember how to initialize this components when edit screen is loaded.

Hi!

You can override postInit() method and manage your component in it.
For instance:

@Override
protected void postInit() {
    if (!PersistenceHelper.isNew(getItem())) {
       yourComponent.setEnabled(enabled);
    }
}

Also, check the documentation about editors.

Thank you, postInit did the job.