Issue with ViewNavigators

Hi,

in 2.0 maybe there is an issue with the navigate or the documentation is missing something.
I have a blank view.
In ‘onBeforeShow’ I added this:
viewNavigators.listView(TourList.class).navigate();
System.out.println(UI.getCurrent().getCurrentView().getId().toString());

The out shows: Optional[TourList.list]
and also the System.out I placed in the TourListListView I can see in the out.
Which means the navigate works somehow.

Now the but:
The Main View is still showing the screen I opened via URL, but not the TourList view where I tried to navigate to.

KR
Roland

attached a demo project…
run it and open it with: http://localhost:8080/BlankViewTest

You will be relinked to the UserListView, but the sidebar section does not get refreshed…

jmix3.zip (171.6 KB)

and when you logout the standard way you get an error message in the log and after that, you can call the http://localhost:8080/BlankViewTest again, but you also do not see any longer the UserListListView…
only when restarting the app, the URL works so far that it shows again the UserListListView…

error:

2023-10-25T17:56:58.497+02:00 INFO 65421 — [nio-8080-exec-4] c.v.f.s.c.AtmospherePushConnection : Timeout waiting for messages to be sent to client before disconnect

java.util.concurrent.TimeoutException: null
at org.atmosphere.cpr.BroadcasterFuture.get(BroadcasterFuture.java:127) ~[atmosphere-runtime-3.0.3.slf4jvaadin1.jar:3.0.3.slf4jvaadin1]
at com.vaadin.flow.server.communication.AtmospherePushConnection.disconnect(AtmospherePushConnection.java:350) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.component.internal.UIInternals.setPushConnection(UIInternals.java:467) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.component.internal.UIInternals.setSession(UIInternals.java:419) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinSession.removeUI(VaadinSession.java:620) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinService.lambda$fireSessionDestroy$20ed7015$1(VaadinService.java:617) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.component.UI.accessSynchronously(UI.java:483) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.component.UI.accessSynchronously(UI.java:444) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinService.lambda$fireSessionDestroy$9c853e43$1(VaadinService.java:607) ~[flow-server-24.0.9.jar:24.0.9]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at com.vaadin.flow.server.VaadinService.runPendingAccessTasks(VaadinService.java:2024) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinSession.unlock(VaadinSession.java:711) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1990) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinService.accessSession(VaadinService.java:1957) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinSession.access(VaadinSession.java:1015) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinService.fireSessionDestroy(VaadinService.java:598) ~[flow-server-24.0.9.jar:24.0.9]
at com.vaadin.flow.server.VaadinSession.valueUnbound(VaadinSession.java:207) ~[flow-server-24.0.9.jar:24.0.9]
at org.apache.catalina.session.StandardSession.removeAttributeInternal(StandardSession.java:1758) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.session.StandardSession.expire(StandardSession.java:844) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.session.StandardSession.expire(StandardSession.java:727) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.session.StandardSession.invalidate(StandardSession.java:1160) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.session.StandardSessionFacade.invalidate(StandardSessionFacade.java:115) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler.logout(SecurityContextLogoutHandler.java:72) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.authentication.logout.CompositeLogoutHandler.logout(CompositeLogoutHandler.java:54) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:93) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:117) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:62) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:233) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:191) ~[spring-security-web-6.1.0.jar:6.1.0]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:352) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:268) ~[spring-web-6.0.9.jar:6.0.9]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.0.9.jar:6.0.9]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.9.jar:6.0.9]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:166) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:894) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.8.jar:10.1.8]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

Hi, Roland!

I’ve looked at the attached project and can highlight a few points that will give you some context.
It’s worth clarifying from the outset that Vaadin client-server interaction has some limitations.

So navigation in this case will not suit you.

Let’s clarify from the beginning - the side menu is a nested component on the MainView.
Now, take a look at this: @Route(value = "BlankViewTest", layout = MainView.class)

Since you tried to navigate from the BlankView, whose layout is MainView, your side menu was not redrawn after authentication.
So you still see the side menu from the anonymous user role (can be seen in the user indicator at the bottom of the side menu).

When you try to navigate to UserList, you just open it in the MainView layout. Thus the side menu is still not redrawn.

In order to redraw the side menu and completely update the access rights for the current authenticated user, you need to make hard navigation.
In other words, you must completely recreate MainView.

You can use the com.vaadin.flow.component.page.Page class API.

Something like that:

  • com.vaadin.flow.component.page.Page#setLocation(java.lang.String)

You can also use UI.getCurrent().getPage() to access the current page.

Be careful, navigation is performed asynchronously with sending a request to the client sice (js call), so info about the client side on the server may not be relevant until the fetching.

So you need to use something like that:

    @Subscribe
    public void onAttachEvent(final AttachEvent event) {
        try {
            loginViewSupport.authenticate(
                    AuthDetails.of("admin", "admin")
            );
        } catch (final BadCredentialsException | DisabledException | LockedException | AccessDeniedException e) {
            System.out.println("login failed ");
        }

        UI.getCurrent().getPage().setLocation("users");
    }

When opening the view this way, the current page opens in a clean way and recreates all components.

Regards,
Dmitriy

Hi,
thx for explanation.
Will try that next week.
I also had a look at that routing stuff,
but still on the learning path to really understand how Vaadin is handling it :slight_smile:
Will paste my results here next week…
KR
Roland

1 Like