Reputation: 405
i am creating a login page with GWT. If the login is successful do I just show/hide elements with object.setVisible(bool) or is there an other, proper way to do it?
Thanks
Upvotes: 0
Views: 313
Reputation: 20920
Yep, that'd be more or less the right way to do it. Whenever you need to hide something you can just do:
thing.setVisible(userLoggedIn());
This will hide it when it needs to be hidden, and show it when it needs to be shown.
If you find you have a lot of things that need to be hidden, you might want to consider registering them all in a central place and iterating over them to show/hide them all in one place in your code.
If you have a ton of things that need to be shown/hidden conditionally, and if there's a lot of code that only needs to run for logged-in users, and you expect logged-out users to use your site for anything meaningful, you could go so far as to generate a deferred binding permutation based on the user's logged-in state, so that logged-out users don't have to download all the logged-in user code needlessly. But that's a more advanced topic.
Upvotes: 0
Reputation: 16060
I would suggest to add / remove the elements from DOM.
For example: If you just hide a Button by setting it invisible for logged-off user. The evil logged-off user may make it visible with browser-development tools and will get features which are for logged-in users only.
Upvotes: 1