rainer198
rainer198

Reputation: 3263

Best practice for storing globally required objects in GWT

I am starting to develop a GWT application in MVP style (GWTP) and which uses Spring security for authentication and authorization on server side.

In many views of the application, I have to enable or disable controls with respect to a granted authority of the current user. I already have an RPC service which provides access to a userDetailsDto containing all the necessary information.

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

Since the user rights are relevant in many presenters, I would have to pass it around everywhere. Alternatively, I could set an RPC service instance in every presenter and requets the user details each time (probably cached on client-side). But i don't like the idea of having a user RPC service in each presenter just for this purpose.

To be honest, I'd rather would prefer a central registry where to put the UserDetails object and which is accessable from anywhere in my app. Is there already such a registry in GWT?

As in my example, you might often be confronted with horizontally used objects. How to deal with them in GWT?

Upvotes: 7

Views: 2506

Answers (2)

Riley Lark
Riley Lark

Reputation: 20890

I inject an "AppState" object into all of the presenters that need to know things like the rights of the user logged in, their preferences, etc. I prefer injection to a public static variable because it feels more controlled, is easier to mock up in tests, and the extra typing forces me to consider whether each object really needs access to the global data.

Upvotes: 5

koma
koma

Reputation: 6566

Simply store your current user in public static variable. It will be accessible from everywhere.

Upvotes: 5

Related Questions