Cant attach a focus listener to a DateField and Currency Field

I’m trying to have context menus for manually created components
Date field and Currency field are having cast issues.

DateField dateField = uiComponents.create(DateField.class);
                dateField.setStyleName("caption-on-left");
                dateField.setCaption(caption);
                dateField.unwrap(com.vaadin.ui.DateField.class).addFocusListener(event -> {
                    loadContextMenu(dateField);
                });
                field = dateField;

java.lang.ClassCastException: Cannot cast com.haulmont.cuba.web.widgets.CubaCssActionsLayout to com.vaadin.ui.DateField

CurrencyField currencyField = uiComponents.create(CurrencyField.class);
            currencyField.setStyleName("caption-on-left");
            currencyField.setCaption(caption);
            currencyField.unwrap(com.vaadin.ui.TextField.class).addFocusListener(event -> {
                loadContextMenu(currencyField);
            });
            field = currencyField;

Labels,Radio buttons, and checkboxes wont do anything. they don’t have the on focus I tried the contextClick but it does nothing.

Label labelField = uiComponents.create(Label.class);
            labelField.unwrap(com.vaadin.ui.Label.class).addContextClickListener(event -> {
                loadContextMenu(labelField);
            });
            labelField.setValue(caption);
            field = labelField;

maybe its easier to put the listener on the Hbox that contains the component but havent been sucessful on that either

HBoxLayout layout = uiComponents.create(HBoxLayout.class);
    layout.unwrap(com.vaadin.ui.ComponentContainer.class).addListener(event -> {
        notifications.create().withCaption("asdasd").show();
        templateEditHelper.loadContextMenu(field);
    });

Thank you for all the help !!!

Hi.

The problem with exception occurs due to incorrect unwrapping operations.

Cuba component DateField cannot be unwrapped to com.vaadin.ui.DateField because the internal component of DateField is a com.haulmont.cuba.web.widgets.CubaCssActionsLayout.

The same situation with CurrencyField, it cannot be unwrapped to com.vaadin.ui.TextField.class because the internal component of CurrencyField is a CubaCurrencyField.

We will try to find out what’s wrong with adding FocusListener.
Check out the example how ContextMenu could be implemented.

Regards,
Nadezhda