Hi everyone. I try to use @UIScope in my mainlayout class that store the menu to use in another
class some UI component of the mainlayout. Is it possible to use the UIScope implementation in service class ?
Like it’s explain in the doc, in a service class i implement on the constructor like that
@Service
public class ComposantTService
{
public ComposantTService(@Autowired UIMainlayout argUiMainmayout)
{
but on the compilation i have this error
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.steel.dao.ComposantService required a bean of type 'com.steel.UIMainlayout' that could not be found.
Action:
Consider defining a bean of type 'com.steel.UIMainlayout' in your configuration.
And I have define the class UIMainlayout
@UIScope
public class UIMainlayout {
private Span msgBadge;
private Dialog dlgNotif;
private SteelButton btNotif;
public UIMainlayout() {
Ok thanks for your help. I add this in my class and now another error
Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'UIMainlayout': Scope 'vaadin-ui' 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
(@Autowired annotation should not be mandatory)
Like Rubén mentioned, you need to register to the layout with @Component or @Service
To your newest error, I was just to write about this: ComposantTService has a Application Scope (default), but UIMainLayout can only be created when a UI has been created. When the application starts, I think, all application scoped beans are created, but there is no UI yet that can be connected to UIMainlayout.
Either make ComposantTService UI scoped too,
or switch the dependence: UIMainlayout(@Autowired ComposantTService service)
If you can describe your “real” problem we might be able to help with an appropriate solution. You normally don’t want to “hardwire” access to your main layout.
Ok. In my “MainLayout”, I’ve created a notification button. So in differrent view of my application,
I want to change the number display of my “notificatoin button”. That why I want to access of this component created in the “MainLayout”.
I’m sorry but I don’t see how to solve my problem with the cookbook solution.
I understand in the example that when I click on an element of the Mainlayout (in my environment) I can handle other component. But my use case is when I click on element of other view, I want to change state of Mainlayout component.
Thank you all of you for your help. For the moment the UIScope method work fine (I use only in viex not in service class). I will check next week the timing for your method @ladam
The main layout is usually the parent of the view or the child of the UI.
UI scope means the annotated component will be kept if you are on the same UI ( which is almost a browser tab). I don’t think it’s the solution for your problem.