View other than Component?

This is just a theoretical/ideological question:

View description from javadoc: Interface for all views controlled by the navigator. Each view added to the navigator must implement this interface. Typically, a view is a Component. Does it exist a use case, when View can be something other than a Component?
When trying to navigate to a view, that not implements Component interface, the IllegalArgumentException is thrown: View is not a component: If it must be a Component, why View interface does not extend Component interface?



the exception comes from an implementation of the ViewDisplay interface (there are two implementations in the framework). Both of those check that the view is an instance of component. However, you could write and provide your own ViewDisplay implementation to the Navigator, which could then accept basically anything and display something based on the provided view type, whatever it might be.

So I guess the answer to your question is that Component interface is not extended to keep it as customizable as possible.

One use case for this is when a view logically consists of multiple components that might not be adjacent in the component hierarchy. Another would be a case where all views share the same component hierarchy, each of them just changes some of the state of the shared components.

But still each view must implement Component interface - in other case you can’t navigate to it.

No; as Teppo said, all you need is to set a custom ViewDisplay that knows how your views should be displayed - it could even be a no-op in some cases if the views itself handle everything in their enter() method.

OK I understand. But can’t find any useful use case of implementing your own display, that shows something other than Component ;-).

In some applications, the logical view is separated from the actual components to display - this is another (optional) level of abstraction that can support e.g. having multiple different actual views for a logical view.

As an example of a use case, you could have an “edit” view and three different components (selected by the ViewDisplay) used based on whether the user is on a desktop computer, on a tablet or on a mobile phone.

It seems reasonable. Thank you all for contributions to discussion. :slight_smile: