DTO's are common for many users?


I’m new to Vaadin and quite new to Java at all (approx. 2 yrs of learning and programming). I used to work with GWT/GXT since the beggining of my programmer-career :slight_smile: but since it’s quite ugly - I’ve decided to move to Vaadin.

And here’s the problem: GWT has seperated client-side and server-side. It’s obvious, that DTO in client-side can’t be accessed from server-side and the opposite way as well.

But now, in Vaadin, there’s no such division, so I have a trouble with making even the simpliest UserDTO.

By trouble, I mean that, after user logs on (let’s say: User A) to the app - user data got injected into dto, and later I can access that data w/o any problem. That’s ok. But the real problem begins when second user logs on (User B ) from some other computer/browser. Then - the DTO of user A gets ovewrited by user’s B data.

I’ve created a simple button on top menubar with caption maden by name and surname of logged user. When user is logging on - his/hers name and surname are stored in DTO, and button gets the data from DTO. Let’s say - User A logs on and the button caption will be: User A., Theb User B logs on from some other computer and the button caption for him is: User B. Now, if I will refresh the app-page where User A is logged - after refresh, the button caption wil be User B for both users.

Can anyone please explain me, what I’m doing wrong?
Thank you in advance
Best regards

Most likely you are using a static keyword somewhere. In Vaadin, since everything is serverside, the usage of static is strongly discouraged, because that object will be shared with all user. This results in exactly the kind of issue you are experiencing.

Use normal objects without static and you should be fine. If you need to store the object somewhere, the UI class is a good place to start; you can get a reference to the UI object that is currently active with UI.getCurrent(). Cast the result to YourUIClass, and you can access anything you have stored in it. This also ensures proper garbage collection once the user logs out and the UI object is destroyed.

Thank you for explanation. In fact - I’ve used static references everywhere :expressionless: I’ve downloaded vaadin dashboard demo and looked into code how ‘they’ did it. Now, I’ve rebuilt whole app and data transport methods and problem described in first post - does not occure anymore.

Thank you very much for pointing me in the right direction :slight_smile:

You are very welcome. This is a common issue for people programming single-user environments (desktop or javascript).

For the last two years I’ve been using GWT/GXT and there’s clear separation between server side and client side (one package com.myproject.server and the second com.myproject.client). That was really simple, however - GXT is so ugly… I’ve never understood why clients wants to buy that soft :smiley: Maybe the pricing… :stuck_out_tongue:

Anyway - now everything is working fine and now I see how simple is programming with vaadin :slight_smile:

Good to hear. Have fun! :slight_smile:

Have you tried Hibernate? Is a good point to start and working with DTOs, DAOs and Data Model. Also, you should take into account sessions, which hibernate helps you a lot.

To be honest - I haven’t tried it yet. I’ve heard a’lot good things about hibernate, also I’ve been working with hibernate on previous project, but it wasn’t me, who implemented it. I’ve been only correcting some gui problems… Now, when I’ve decided to build my own app - I have to learn lot of things, but first - I need running demo, so I can get some orders, and earn some money to extend my knowledge :slight_smile:

I see your point ^^. Good luck!