I have a situation in my application where I have a view page for an entity. These entities can be either by themselves, or link to each other as parent/child. In a situation where I'm viewing a child, I want the user to simply press a button to navigate to the parent. This entails opening up the exact same page via the same route. However, navigate does not reload the page when navigating to itself. I need it to, because I'm dealing with dozens of fields and submodules that all need to be rebuilt and repopulated. Presently, what I'm doing is this:
if (myEntity.getParent() != null) { myMenu.add(new Button("View Parent", evt -> /*UI.getCurrent().navigate( MyEntityViewUI.class, new RouteParameters(HasUrlParameterFormat.PARAMETER_NAME, String.valueOf(myEntity.getParent().getId())) )*/ UI.getCurrent().getPage().setLocation( GeneralUtils.getAnnotationForClass(MyEntityViewUI.class, Route.class).value() + "/" + myEntity.getParent().getId() ) )); } The commented out portion is what I'd like to do. The setParameter method is invoked, but not the constructor and thus not any of the logic I've currently implemented that actually builds my page. And even if I manually invoked that, I'd have to rewrite 2 layers of abstract parents to properly gut my existing components so that I can just rebuild everything fresh. I'd really prefer to not have to do that if it can be avoided.
The current code I have is using setLocation, but this is hackey and isn't a smooth transition like navigate() is. Plus, I can't just provide the class and RouteParameters via this, hence the manual construction of the string.
Is it possible to force Vaadin to perform a full page reload when navigating to the same Route? I don't really understand why it wouldn't be re-instantiating the navigation target.
I'm using Vaadin 24.6.2.
To clarify, I'm not building things within the constructor. I am utilizing a general BeforeEnter listener in my abstract super class which invokes an abstract initUI() method that is overridden by implementation classes. Part of the problem is that my button and menu in the above is done inside of a customized menu put into the AppLayout's Drawer pane, and even the HasDynamicTitle is utilizing information from the viewed entity.