Register View in Navigator using instances or classes?

Hi,
what is a best practice to use Navigator in Vaadin7:

  1. navigator.addView(“name”, viewInstance);
    or
  2. navigator.addView(“name”, View.class);

Which one is preferred? Are there any pros or cons to use one instead of other?

Thanks,
Vladimir

If your View is stateful, then you should use the viewInstance in the navigator.

If your View don´t have a state than you can use the .class.

When using the class-Method, there is a ClassBasedViewProvider in use.
And on every getView-call there is a new instance of your view created.

When using the instance-method, there´s always your instance returned.

It depends on your requirements what to use.
I prefer using my own ViewProvider which delivers instances.