Programmatically setting focus of textfield in master-detail screen when edit action is triggered

I am using the automatically generated master-detail screen in Cuba 7.2 with a DataGrid.

I need to programmatically set the focus of a particular TextField in the detail section of when the edit action is triggered.

I have tried using myTextField.focus() in the onTableEdit and the onTableEditorOpen event handlers, but without success. Some background code is being called after these events that is overriding the focus I set.

Can anyone suggest how I might achieve my objective?

Hi,

We recommend everyone to observe code of the base screen classes (StandardEditor, StandardLookup, MasterDetailScreen), . We think that it is fairly understandable. Many methods in these classes are designed for extension. It is open source, after all.

In your case you need to override the com.haulmont.cuba.gui.screen.MasterDetailScreen#enableEditControls method in your screen.
Invoke super() and then focus the field you need.

    /**
     * Enables controls for editing.
     * @param creating indicates that a new instance is being created
     */
    protected void enableEditControls(boolean creating) {
        this.editing = true;
        this.creating = creating;
        initEditComponents(true);
        getForm().focusFirstComponent();
    }

Thanks @albudarov . This works perfectly.

I will definitely look at the base screen classes in the future.

Great framework.