1

In Vaadin 8 I am currently developing a Web App and I am struggling with the menu / view management / navigator...
Since I am completely new to servlets and Vaadin, I am not quite sure if my approach will work / if i understood this correctly.
I thought to have understood Vaadin like this:
- The app runs on my server.
- For every user that accesses it, a new instance of my UI is created

Now I want to have a nice design to manage the navigator (which maps strings to views) and my menu (which needs a String to display and the key string to pass to the navigator).

My current idea is to use an Enum like this:

public Enum ViewManager {

  HOME("home", "Home", new HomeView()),
  ANOTHER_VIEW("another", "Another View", new AnotherView());

  private final String stateName, menuName;
  private final View view;

  MenuEntry(String stateName, String menuName, View view) {
    this.stateName = stateName;
    this.menuName = menuName;
    this.view = view;
}

Then I could develop the Menu to create entries by iterating over ViewManager.values().
I could add views to the UI navigator using navigator.addView(String, view) (I dislike navigator.addView(String, Class<View>) since it will create a new view instance every time one navigates.

Long story short: Will this work or will I have interference between multiple users when they change view attributes. (especially dangerous when users try to access sensible data like email, password,... for example in a loginView)

goerlibe
  • 120
  • 1
  • 12
  • 2
    In this form you'll probably have some issues, because enums are constants in Java, so you'll always have one instance of each value in the JVM. In consequence, you'll have the same view instances shared among the users. Not 100% sure without trying a code, but I suspect will fail immediately, as a Vaadin component (eg: a button) can only have 1 parent at a time, and as soon as you have 2 users your app will try to use the same component instances for both of them. – Morfic Jul 20 '17 at 23:30
  • I have a question: why you dont want to give a shot to vaadin + spring? By the way there is @UIScope which creates annotated object and maintains it until session expired or UI exists (happens when user navigates to other website or closes a browser) – Malakai Jul 22 '17 at 14:04

0 Answers0