this code. want following. im getting exception @ getcomponent(0) in loginstep1 class. how should resolve this. im new in vaadin. if approach wrong guidance required.
public class login extends verticallayout implements view { public static string viewname = "login"; public void enter(viewchangeevent event) { removeallcomponents(); customlayout viewscreen = new customlayout("screens/screen-login"); component step1 = new loginstep1().getloginstep1(); viewscreen.addcomponent(step1, "login-steps"); addcomponent(viewscreen); } }
@suppresswarnings("serial") public class loginstep1 extends login { public component getloginstep1() { customlayout stepscreen = new customlayout("components/screens/login-step1"); button loginbtn = commoncomponents.getbutton("login", "btn btn-green btn-block"); loginbtn.addclicklistener(new button.clicklistener() { @override public void buttonclick(clickevent event) { // line gives me exception. customlayout currentlayout = (customlayout) getcomponent(0); currentlayout.addcomponent(new loginstep2().getloginstep2(request, posinforesponse.getbody()), "login-steps"); } }); } stepscreen.addcomponent(loginbtn,"login-btn"); return stepscreen; }
it gives following exception
com.vaadin.server.serverrpcmanager$rpcinvocationexception: unable invoke method click in com.vaadin.shared.ui.button.buttonserverrpc @ com.vaadin.server.serverrpcmanager.applyinvocation(serverrpcmanager.java:160) @ com.vaadin.server.serverrpcmanager.applyinvocation(serverrpcmanager.java:118) @ com.vaadin.server.communication.serverrpchandler.handleinvocations(serverrpchandler.java:408) @ com.vaadin.server.communication.serverrpchandler.handlerpc(serverrpchandler.java:273) @ com.vaadin.server.communication.uidlrequesthandler.synchronizedhandlerequest(uidlrequesthandler.java:79) @ com.vaadin.server.synchronizedrequesthandler.handlerequest(synchronizedrequesthandler.java:41) @ com.vaadin.server.vaadinservice.handlerequest(vaadinservice.java:1409) @ com.vaadin.server.vaadinservlet.service(vaadinservlet.java:364) @ javax.servlet.http.httpservlet.service(httpservlet.java:729) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:291) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:239) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:217) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:106) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:502) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:142) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:79) @ org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:616) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:88) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:518) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1091) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:673) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1500) @ org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1456) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source) caused by: java.lang.reflect.invocationtargetexception @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ com.vaadin.server.serverrpcmanager.applyinvocation(serverrpcmanager.java:158) ... 29 more caused by: com.vaadin.event.listenermethod$methodexception: invocation of method buttonclick in com.herman.login.loginstep1$1 failed. @ com.vaadin.event.listenermethod.receiveevent(listenermethod.java:528) @ com.vaadin.event.eventrouter.fireevent(eventrouter.java:198) @ com.vaadin.event.eventrouter.fireevent(eventrouter.java:161) @ com.vaadin.server.abstractclientconnector.fireevent(abstractclientconnector.java:1003) @ com.vaadin.ui.button.fireclick(button.java:377) @ com.vaadin.ui.button$1.click(button.java:54) ... 34 more caused by: java.lang.indexoutofboundsexception: index: 0, size: 0 @ java.util.linkedlist.checkelementindex(unknown source) @ java.util.linkedlist.get(unknown source) @ com.vaadin.ui.abstractorderedlayout.getcomponent(abstractorderedlayout.java:414) @ com.herman.login.loginstep1$1.buttonclick(loginstep1.java:23) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ com.vaadin.event.listenermethod.receiveevent(listenermethod.java:508) ... 39 more
some things still unclear since haven't answered comments, i'm unsure of 3 implementations (login
, loginstep1
or loginstep2
) you're using view navigation navigator component. however, looking @ login
& loginstep1
, can see may want reconsider in current design: you're creating new instances of inherited classes , invoking methods on them, instead of using current instances...
since sources loginstep2
not available, i'll try cover other 2 scenarios:
1) suppose you're navigating instance of login
.
when
enter
method called, new instance ofloginstep1
created , added component list insidecustomlayout
.when click login button,
getcomponent(0)
invoked on new instance ofloginstep1
not inheritlogin
instance used in navigation, hence contains 0 components leading exception
2) suppose you're navigating instance of loginstep1
, extends login
.
when enter event triggered ,
enter
method inherited superclass executed, new instance ofloginstep1
created , added component list insidecustomlayout
.when click login button,
getcomponent(0)
invoked on new instance ofloginstep1
has nothing currentloginview1
instance used in navigation, hence contains 0 components leading exception
in conclusion, more related basic java inheritance concepts vaadin, , main question may component step1 = new loginstep1().getloginstep1(); // <= why create new instance?
public class login extends verticallayout implements view { public static string viewname = "login"; public void enter(viewchangeevent event) { removeallcomponents(); customlayout viewscreen = new customlayout("screens/screen-login"); component step1 = new loginstep1().getloginstep1(); // <= why create new instance? viewscreen.addcomponent(step1, "login-steps"); addcomponent(viewscreen); } }
Comments
Post a Comment