Best practices for storing global objects in GWT

I am starting to develop an MVP-style GWT application (GWTP) that uses Spring for server-side authentication and authorization.

In many application views, I need to enable or disable controls in relation to the granted privileges of the current user. I already have an RPC service that provides access to userDetailsDto, which contains all the necessary information.

Now my question is: what is the best place to store for the DTO user on the client side?

Since user rights are relevant in many speakers, I would have to pass it on everywhere. Alternatively, I could install an instance of the RPC service in each master and request user data each time (perhaps cached on the client side). But I do not like the idea of ​​having an RPC user service in each host for this purpose only.

Honestly, I would prefer to use a central registry where to place the UserDetails object and which can be obtained from anywhere in my application. Is there such a registry in GWT?

As in my example, you can often encounter objects used horizontally. How to deal with them in GWT?

+7
source share
2 answers

Just save the current user in a public static variable. It will be available everywhere.

+5
source

I embed the "AppState" object in all speakers who need to know such things as the rights of a user registered on the network, their preferences, etc. I prefer injecting a public static variable because it feels more controlled, easier to layout in tests, and extra text input makes me wonder if every object needs access to global data.

+4
source

All Articles