Ich habe MyUI KlasseWie bekomme ich die UI-Instanz in CDIView in Vaadin?
@Theme("mytheme")
@CDIUI("")
public class MyUI extends UI {
@Inject
LoginView loginView;
@Override
protected void init(VaadinRequest vaadinRequest) {
setContent(loginView);
}
...
ich eine Ansicht mit einem Init-Methode mit @PostConstruct
@UIScoped
@CDIView(LoginView.VIEWNAME)
public class LoginView extends VerticalLayout implements CustomView {
@PostConstruct
public void initView() {
//initializations elements
Component loginForm = buildLoginForm();
addComponent(loginForm);
setComponentAlignment(loginForm, Alignment.MIDDLE_CENTER);
Notification notification = new Notification("Demo");
notification.setDescription("<span>DEMO</span>");
notification.setHtmlContentAllowed(true);
notification.setStyleName("tray dark small closable login-help");
notification.setPosition(Position.BOTTOM_CENTER);
notification.setDelayMsec(20000);
notification.show(Page.getCurrent()); // NullPointerException
}
}
Die stacktrace kommentierte haben ist:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:98)
... 72 more
Caused by: java.lang.NullPointerException
at com.vaadin.ui.Notification.show(Notification.java:378)
at com.test.claspina.view.LoginView.initView(LoginView.java:103)
... 77 more
Meine Frage ist Wie bekomme ich die UI-Instanz, um die Elemente meiner Ansicht zu rendern?
ich eine Teillösung alle Definitionen von Elementen in eine configure Methode gefunden setzen, auf diese Weise:
public void configure() {
//initializations elements
Component loginForm = buildLoginForm();
addComponent(loginForm);
setComponentAlignment(loginForm, Alignment.MIDDLE_CENTER);
Notification notification = new Notification("Demo");
notification.setDescription("<span>DEMO</span>");
notification.setHtmlContentAllowed(true);
notification.setStyleName("tray dark small closable login-help");
notification.setPosition(Position.BOTTOM_CENTER);
notification.setDelayMsec(20000);
notification.show(Page.getCurrent());
}
Und
loginView.configure();
setContent(loginView);