Search in sources :

Example 11 with View

use of com.vaadin.flow.router.legacy.View in project flow by vaadin.

the class ViewRendererTest method testViewInstantiationCustomization.

@Test
public void testViewInstantiationCustomization() {
    // override default implementation of reusing the views if possible
    ViewRenderer renderer = new TestViewRenderer(TestView.class, ParentView.class) {

        @Override
        protected <T extends View> T getView(Class<T> viewType, NavigationEvent event) {
            // always return a new view
            return ReflectTools.createInstance(viewType);
        }
    };
    renderer.handle(dummyEvent);
    View view1 = dummyEvent.getUI().getInternals().getActiveViewChain().get(0);
    View parentView1 = dummyEvent.getUI().getInternals().getActiveViewChain().get(1);
    renderer.handle(dummyEvent);
    View view2 = dummyEvent.getUI().getInternals().getActiveViewChain().get(0);
    View parentView2 = dummyEvent.getUI().getInternals().getActiveViewChain().get(1);
    Assert.assertNotSame(view1, view2);
    Assert.assertNotSame(parentView1, parentView2);
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) ViewRenderer(com.vaadin.flow.router.legacy.ViewRenderer) HasChildView(com.vaadin.flow.router.legacy.HasChildView) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) View(com.vaadin.flow.router.legacy.View) Test(org.junit.Test)

Aggregations

HasChildView (com.vaadin.flow.router.legacy.HasChildView)11 View (com.vaadin.flow.router.legacy.View)11 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)10 Test (org.junit.Test)10 TestViewRenderer (com.vaadin.flow.router.legacy.TestViewRenderer)7 Element (com.vaadin.flow.dom.Element)3 NavigationEvent (com.vaadin.flow.router.NavigationEvent)2 ViewRenderer (com.vaadin.flow.router.legacy.ViewRenderer)2 HasElement (com.vaadin.flow.component.HasElement)1 HashMap (java.util.HashMap)1