开发者

TabLayoutPanel - Show tabs based on roles

开发者 https://www.devze.com 2023-03-06 19:59 出处:网络
I\'m developing a GWT-Application where the navigation is mainly a TabLayoutPane, where each Tab represents a different functionality. What I need is to only show tabs the user is allowed to see (each

I'm developing a GWT-Application where the navigation is mainly a TabLayoutPane, where each Tab represents a different functionality. What I need is to only show tabs the user is allowed to see (each user has a role like user or admin).

The problem is I don't know how to achieve this, especially with UIBinder.

Here's what I thought of:

  1. Don'开发者_运维知识库t use UIBinder and build the TabLayoutPanel programmatically.
  2. Use UIBinder and just hide certain tabs based on each users role (which sounds like it would be quite inefficient).

Or are there better ways to achieve something like this?


I would go with approach number one as it is much cleaner, imho. However, make sure that you don't use it as security feature and don't show any sensitive information that non admin is not allowed to see. Since all construction will occur in javascript in the browser, it will be fairly simple to fool browser into showing admin tabs without appropriate authorization.


I suggest option 2.

GWT produces a smaller amount of JavaScript because the tabs in UiBinder can be turned into HTML and CSS. To hide a tab and its content:

    aTabPanel.getTabWidget(0).setVisible(false);
    aTabPanel.getTabWidget(0).getParent().setVisible(false);

Not a pretty bit of code but the second line ensures the tab itself is hidden in addition to the tab's content.

0

精彩评论

暂无评论...
验证码 换一张
取 消