java ee - How to get UI instance in CDIView in Vaadin? -


i have myui class

@theme("mytheme") @cdiui("") public class myui extends ui {  @inject loginview loginview;  @override protected void init(vaadinrequest vaadinrequest) {     setcontent(loginview); }  ... 

i have view init method annotated @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      } } 

the stacktrace is:

caused by: java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:498)     @ org.jboss.weld.injection.producer.defaultlifecyclecallbackinvoker.invokemethods(defaultlifecyclecallbackinvoker.java:98)     ... 72 more  caused by: java.lang.nullpointerexception     @ com.vaadin.ui.notification.show(notification.java:378)     @ com.test.claspina.view.loginview.initview(loginview.java:103)     ... 77 more 

my question how ui instance use during render elements of view.

i found partial solution putting definitions of elements configure method, way:

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()); } 

and calling before setcontent in ui

loginview.configure(); setcontent(loginview); 

finally, of co-worker, found solution:

it's necessary use cdiviewprovider way

@theme("mytheme") @cdiui("") public class myui extends ui {  @inject loginview loginview;  @inject private cdiviewprovider viewprovider;  @override protected void init(vaadinrequest vaadinrequest) {     navigator navigator = new navigator(this, this);     navigator.addprovider(viewprovider);     navigator.navigateto("login"); } 

and class, define name of view, , put definitions of elements of view in entering method

@uiscoped @cdiview(loginview.viewname) public class loginview extends verticallayout implements customview {      public static final string viewname = "login";     //...    //other methods    //...      @override    public void enter(viewchangelistener.viewchangeevent event) {       //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());     } } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -