Navigate to window with a public one-arg-constructor.

In vaadin 8 i could navigate to a window with one-arg-constructor by the following code

	private Button showTitleView() {
		titleButton = new Button("Title", new Button.ClickListener() {
			@Override
			public void buttonClick(ClickEvent event) {
				masterDetailContent.removeAllComponents();
				masterDetailContent.addComponent(new TitleView(argument));
			}
		});
		return titleButton;
}

In this way i could navigate to TitleView with one argument.

How can i navigate in vaadin 12 by using an one-arg-consrtuctor?

Hi,

In your example you don’t “navigate” to a view. (You don’t use Navigator)

But to navigate to one arg view (or a route) in vaadin 10, you can use ui.navigate(TitleView.class, argument)

Here the documentation https://vaadin.com/docs/v12/flow/routing/tutorial-routing-navigation.html

You can also use a routerlink:
menu.add(new RouterLink(“Greeting”, GreetingComponent.class, “default”));

thanks for your answer

My argument is an object, injected as TitleService service (@Inject TitleService service;)

When i use the code

		NativeButton button = new NativeButton("Visor");
		button.addClickListener( e-> {
		     button.getUI().ifPresent(ui -> ui.navigate("TitleView", service));
		});

I get the error

The method navigate(String, QueryParameters) in the type UI is not applicable for the arguments (String, TitleService)

I think route argument is for “argument” (like id of your element) not a service.

Why don’t you inject your TitleService in your TitleView ?
(I never try J2ee injection with Vaadin but I think it’s like spring)

PS: I think you’ve got the compilation error because your titleView does not implement HasUrlParameter . (but in my opinion it’s better to inject your service in TitleView intead of using argument)

It is nested navigation.

First navigation level i make with CDI. Here i inject the service.

But in the second naviagtion level CDI is not possible.

But i need in the second Level again the same service.

This is my problem.

Sebastian from you company told me half a year ago, that nested navigation with CDI will come one time.

I dont know when nested CDI will come, but as far as i know it is not in vaadin 12.