KaesDingeling / Hybrid-Menu

Hybrid-Menu Widget for Vaadin Application
Apache License 2.0
22 stars 13 forks source link

Version 3.0.5 for Vaadin 10 - Button click throws ClassCastException #49

Closed LT-AMC closed 6 years ago

LT-AMC commented 6 years ago

Hi, I just tested out your component with version 3.0.5 for Vaadin 10 and it looks very promising! I just can't get the HMButtons to work properly. If I add one with a ClickListener and click it, I get a ClassCastException for ClickEvent.

Here is the code I used:

MenuConfig config = new MenuConfig();
        HybridMenu hybridmenu = new HybridMenu() {
            @Override
            public boolean init(VaadinSession aVaadinSession, UI aUi) {
                this.withConfig(config);
                return true;
            }
        };

        hybridmenu.getLeftMenu().add(HMButton.get().withCaption("Click").withClickListener( (e) -> System.out.println("click")));

Maybe you also have some insight on the instantiation of HybridMenu. I've seen some examples using HybridMenu.get() but it seems to be missing in the 3.0.5 version.

Anyways, this is the stack trace I get when clicking the created HMButton:

java.lang.ClassCastException: com.vaadin.flow.component.HasClickListeners$ClickEvent cannot be cast to com.vaadin.flow.component.ClickEvent
    at com.vaadin.flow.component.ComponentEventBus.lambda$fireEvent$1(ComponentEventBus.java:125)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:125)
    at com.vaadin.flow.component.ComponentEventBus.handleDomEvent(ComponentEventBus.java:291)
    at com.vaadin.flow.component.ComponentEventBus.lambda$addDomTrigger$f72bee39$1(ComponentEventBus.java:182)
    at com.vaadin.flow.internal.nodefeature.ElementListenerMap.lambda$fireEvent$0(ElementListenerMap.java:203)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at com.vaadin.flow.internal.nodefeature.ElementListenerMap.fireEvent(ElementListenerMap.java:203)
    at com.vaadin.flow.server.communication.rpc.EventRpcHandler.handleNode(EventRpcHandler.java:58)
    at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:63)
    at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:377)
    at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$0(ServerRpcHandler.java:367)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:367)
    at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:309)
    at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:89)
    at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
    at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1496)
    at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:335)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

Hope you can look into this issue, as we would love to use your component :)

KaesDingeling commented 6 years ago

Please see the example for Vaadin 10. I've created an extra branch for this. The Master Branch is Vaadin 8.

https://github.com/KaesDingeling/Hybrid-Menu/tree/vaadin10/HM-Demo/src/main/java/de/kaesdingeling/hybridmenu/demo

KaesDingeling commented 6 years ago

To the exception I would have to know which version of Vaadin 10 you are using, because Vaadin changed a lot during the beta versions.

LT-AMC commented 6 years ago

I see, so you're always supposed to extend Hybridmenu and the .get() will not be implemented again? We are on beta 8 right now, I could try a newer version.

KaesDingeling commented 6 years ago

Exactly, unfortunately I still haven't gotten around to writing a documentary. Since the navigator has changed from Vaadin 8 to 10 to the "router", I have adapted the structure accordingly as I consider it best. My demo uses the Beta 10.

LT-AMC commented 6 years ago

Guess that makes sense, but I didn't look to deep into the routing stuff yet. Updated to beta 10 and it works! Thanks for the insanely fast support, really looking forward to use this component, keep up the good work :)

KaesDingeling commented 6 years ago

Thank you very much. I'm glad. I try to keep up with the beta versions of Vaadin 10. The routing in Vaadin 10 seems confusing, but if you have read in https://vaadin.com/docs/v10/flow/routing/tutorial-router-layout.html then you can handle it quite well. I am currently also in the process of raising my own projects to Vaadin 10, so some changes might be included in the HybridMenu.