Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route not found issue #60

Closed
thigg opened this issue Jan 21, 2021 · 3 comments
Closed

Route not found issue #60

thigg opened this issue Jan 21, 2021 · 3 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@thigg
Copy link
Contributor

thigg commented Jan 21, 2021

I'm getting RouteNotFound Errors after upgrading from 1.1.x to 1.2.8.

We're setting up with 2 packages:

routes = new Routes().autoDiscoverViews("company.view.view").autoDiscoverViews("company.testroutes");

initializing our own Servlet because we need weld:

MockVaadin.setup(MockedUI::new, new WeldMockVaadinServlet(routes, weld));`

Servlet and Service look like this:

public class WeldMockVaadinServlet extends MockVaadinServlet {

    private WeldInitiator _weld;

    public WeldMockVaadinServlet(final Routes routes, final WeldInitiator weld) {
        super(routes);
        _weld = weld;
    }

    @SneakyThrows
    @NotNull
    @Override
    protected VaadinServletService createServletService(@NotNull final DeploymentConfiguration deploymentConfiguration) {
        CdiMockService cdiMockService = new CdiMockService(_weld, this, deploymentConfiguration);
        cdiMockService.init();
        return cdiMockService;
    }
}

public class CdiMockService extends MockService {

    private final WeldInitiator _weld;

    public CdiMockService(final WeldInitiator weld, @NotNull final VaadinServlet servlet,
                          @NotNull final DeploymentConfiguration deploymentConfiguration) {
        super(servlet, deploymentConfiguration, MockedUI::new);
        System.setProperty("vaadin.i18n.provider",
                "company.infrastructure.translation.TranslationProvider");
        _weld = weld;
        addSessionInitListener(new SessionListener());
    }


    @Override
    protected Instantiator createInstantiator() throws ServiceException {
        BeanManager beanManager = _weld.getBeanManager();
        return new KaribuVaadinCDIInstantatior(this, beanManager);
    }
}

When doing UI.getCurrent().navigate(DefaultView.class, param); (DefaultView is in routes, I checked in the debugger):

com.vaadin.flow.router.NotFoundException: No route found for given navigation target!

	at com.vaadin.flow.router.RouteConfiguration.getUrlForTarget(RouteConfiguration.java:522)
	at com.vaadin.flow.router.RouteConfiguration.getUrl(RouteConfiguration.java:476)
	at com.vaadin.flow.router.RouteConfiguration.getUrl(RouteConfiguration.java:450)
	at com.vaadin.flow.component.UI.navigate(UI.java:865)
@mvysny
Copy link
Owner

mvysny commented Jan 21, 2021

Thank you for letting me know! In your WeldMockVaadinServlet.createServletService() you need to also call routes.register(service.context as VaadinServletContext), right before the return statement. Please take a look at the MockVaadinServlet class.

@mvysny mvysny self-assigned this Jan 21, 2021
@mvysny mvysny added bug Something isn't working question Further information is requested labels Jan 21, 2021
@thigg
Copy link
Contributor Author

thigg commented Jan 21, 2021

yes, that works. Thanks for the quick help!

What do you think how to progress from here. Add this as a note for migration from 1.1 to 1.2?
Provide another way to add CDI?

@mvysny
Copy link
Owner

mvysny commented Jan 21, 2021

I'd propose to add this to the FAQ for now; if there are more users bitten by this then we can create a migration guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants