Revealing to different parent presenters at runtime?
36 views
Skip to first unread message
jon
unread,
May 28, 2012, 9:39:21 AM5/28/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gwt-pl...@googlegroups.com
I have a nested presenter that I want to reveal in different parent presenters depending on if the user has a specific role or not. I'm thinking of exporting the content I want to show as a PresenterWidget and then simply have two different name tokens that reveals that in different root presenters. This works but it would be better to simply have one name token and have the reveal check at runtime. Is this possible? How would you best solve this?
Simon-Pierre Gingras
unread,
Jun 4, 2012, 9:57:39 AM6/4/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gwt-pl...@googlegroups.com
Hi Jon!
Of course, having only one nametoken and having a runtime check for permissions would be a better solution.
When a User logins into your webapp, you should store his User unique id in the javax.servlet.http.HttpSession. HttpSession allows you to store data in key-value pairs. Here, the key would be something like “userIdKey”, and the value would be the actual User’s unique id.
To achieve the runtime check, you should have server-side class (say, CurrentUserProvider) that allows you to retrieve the current user visiting your web app. This CurrentUserProvider will get the current javax.servlet.http.HttpSession, and get the User’s unique id, using the aforementioned “userIdKey”.
Then, you can send back an CurrentUser dto to the client. This dto will contain the current User and a boolean indicating whether the current User is logged in (or not). If the User’s id you retrieved from the HttpSession is null, then it means then current User was not logged in, and vice versa.
Finally, on the client-side, when you retrieve the CurrentUser dto, you can tell if the current user is logged in or not (using the CurrentUser.isLoggedIn field). If the current user is logged in, you will be able to validate his permission level (normal user, or admin, for example).
Using an if-else statement, you will reveal the proper Ui depending on the current user’s privileges.