Problem with @EJB Injection to some Class outside of UI-Class: Entity can't

Hello everybody!

I am trying to do an injection of some Entity (Table from MSSQL) with the help of @EJB.
I can inject this entity easily to UI-Class:

import com.mycompany.backend.testblock.DocuIF
import com.mycompany..models.entity.Document
import javax.ejb.EJB;
import com.vaadin.cdi.CDIUI;
 
@Theme("demo-theme")
@CDIUI("")
public class MyUI extends UI {
 
@EJB  
DocuIF docu;
 
public static class Servlet extends VaadinCDIServlet {
@Override
        protected void servletInitialized() throws ServletException {
       super.servletInitialized();
   //.....................
   }
 
protected void init(final VaadinRequest request) {

List<Document> getallDocu = docu.getAll();  //---- Here the Entity can be perfectly initialised!!!
//..........
  }
}

The problem: I am trying to initialise the same Entity in the class which is outside of UI-Class. I am triyn to inject this Entity in the VerticalLayout Class which implements the View:

[code]
import com.mycompany.backend.testblock.DocuIF
import com.mycompany…models.entity.Document
import javax.ejb.EJB;
import com.vaadin.cdi.CDIView;

public final class ConditionModel extends VerticalLayout implements View {

public static final String VIEW_ID = “dashboard”;

@EJB
DocuIF docu;

@CDIView(value = ConditionModel.VIEW_ID)
// I tried to play with some other annotations : @UIScoped; @ManagedBean; @SessionScoped but it does not help

public ConditionModel() { //constructor

List getallDocu = docu.getAll(); //Here docu = null
//…

}
}
[/code]Please help. How the Entity can be Injected, initialised in the class outside of UI?

As far as I know the @CDIView annotation must be put at class level in this case.

How do you inject your view in the ui? Using navigator and CDIViewProvider or by hand?

At the moment I am not using CDIViewProvider.
The view is a page in the Navigator, which is in UI-Class:

 protected void init(final VaadinRequest request) {
//....
  navigator.addView("condmodel", ConditionModel.class);
}

The page is working properly with some Vaadin-components. Namely with the Spreadsheet.
I tried to inject the table in this page like mentioned and played with some different annotations.
How can i inject in this view correctly?

I think that navigator default view provider does not do dependency injection; you should use CDIViewProvider if you want your field being injected inside the view.

Thank you. I solved the problem with your hint.
Firstly, one should inject the CDIViewProvider into UI Class.

  @Inject
    private CDIViewProvider viewProvider;

and after that one should use in the View-class the Annotation and initialise-method where one shoult initialise the injected Entities:

@CDIView("dashboard") //..................... @PostConstruct // protected void initialize() { List<Document> getallDocu = docu.getAll(); //Here docu = null //..................... } I dont know why somewhere I found that method initialise() must be protected.
Actually it does not work.
But everything else is working now.