The right way to extend AppUI

Hi,

From this post:
https://www.cuba-platform.com/discuss/t/allow-customization-of-appui-error-management/3787
I learned that can extend AppUI using following way:

<bean id="cuba_AppUI" class="com.company.appui.web.CustomAppUI" 
      scope="vaadin"/>

I have gave a try, there will occur some error when app starting:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dashboard_dropComponentsFactory': Unsatisfied dependency expressed through field 'appUI'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cuba_AppUI': Scope 'vaadin' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: Unable to use VaadinSessionScope from non-Vaadin thread
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]

The cause of the error is that the bean’s scope be set to ‘vaadin’ , if i set the scope to ‘prototype’ ,it will seems works fine.

Is it a right way for extending AppUI ?

Hi,

Works for me without any problems. Please note that your UI class must extend AppUI.

public class CustomAppUI extends AppUI {
}

What is this? Is it an addon that tries to use AppUI as injected bean? Most likely you need to update your add-on version.

Hi Yuriy,

Thanks for your reply.

I have checked my code, my AppUI class extend from platform’s AppUI class :
image

About the ‘dashboard_dropComponentsFactory’, it come from the ‘Dashboard’ addon, i used the latest version of the addon.

image

CanvasDropComponentsFactory extends CanvasUiComponentsFactory, in CanvasUiComponentsFactory class AppUI is injected.

My environment :
Platform:7.0.6
Dashboard Addon:3.0.2

Actually, it is a problem of the add-on. I’ve filed the issue CanvasUiComponentsFactory must not inject `AppUI` bean · Issue #19 · cuba-platform/dashboard-addon · GitHub

Hi Yuriy,

Thanks for you confirmed this.

Hi @lugreen,

Please try 3.0.3 dashboard addon version. In this version the issue should be fixed.

Regards,
Evgeny

Hi Evgeny,

I have checked it,now it works fine.

Thanks very much.

Regards,
Ray