How to rederect on page (view) load ?

Hello, the scenario is this: User opens View A and enters URL manually to go to View B. In this case I want to redirect the user to another View, because of security settings. So in my View B, in the enter( ViewChangeEvent event ) method, I wrote this:

Navigator nav = new Navigator(myUIObject, ViewC);
nav.addView("/ViewC",ViewC);
nav.navigateTo("/ViewC");

In this case an error is shown: java.lang.IllegalArgumentException: Trying to navigate to an unknown state... Can anyone help please?

You don´t use your “nav” variable.

You call methods from “navigator” variable

Sorry just a typo mistake, it is the same

Don´t use a new Navigator object.

Use the navigator you already use.

You can get the object with

UI.getCurrent().getNavigator()

I have a MyUI class that extends UI and I am trying to navigate within my View class, which does not extend UI. I cannot call it that way. Within my MyUI class the navigator is fine, but how to deal within the ViewClass.

You cannot display ViewC in ViewC.

You have to give another ViewDisplay/SingleComponentContainer… to the constructor:

Navigator nav = new Navigator(myUIObject, <your container to display ViewC, this cannot be ViewC>);

These are separated classes. In my MyUI class I have a container, but this container is not defined in the other classes. Maybe I am not expressing very well, can you please tell me a way to perform navigation from ViewA to ViewB (not classes that extend UI) ?

Simply use one Navigator for all. Add all Views you need to the Navigator you have in your UI.

When in any enter method of a view you need to change the view just call

UI.getCurrent().getNavigator().navigateTo();

Your other classes don´t need to know about the container in your UI.

Hope this helps, otherwise I don´t know what you want to do

Thank you. I will try and let you know.