Search in sources :

Example 1 with ViewRenderer

use of com.vaadin.flow.router.legacy.ViewRenderer 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) TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) ViewRenderer(com.vaadin.flow.router.legacy.ViewRenderer) TestViewRenderer(com.vaadin.flow.router.legacy.TestViewRenderer) HasChildView(com.vaadin.flow.router.legacy.HasChildView) View(com.vaadin.flow.router.legacy.View) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) Test(org.junit.Test)

Example 2 with ViewRenderer

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

the class RouterConfigurationTest method assertErrorView.

private void assertErrorView(Router router, Class<? extends View> errorView) {
    ViewRenderer errorHandler = (ViewRenderer) router.getConfiguration().getErrorHandler();
    Assert.assertEquals(errorView, errorHandler.getViewType(null));
}
Also used : ViewRenderer(com.vaadin.flow.router.legacy.ViewRenderer)

Example 3 with ViewRenderer

use of com.vaadin.flow.router.legacy.ViewRenderer 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

ViewRenderer (com.vaadin.flow.router.legacy.ViewRenderer)3 NavigationEvent (com.vaadin.flow.router.NavigationEvent)2 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)2 HasChildView (com.vaadin.flow.router.legacy.HasChildView)2 View (com.vaadin.flow.router.legacy.View)2 Test (org.junit.Test)2 TestViewRenderer (com.vaadin.flow.router.legacy.TestViewRenderer)1