Set Theme by Role or User

How to Set a different theme for different users based on the user ID or user Role

The logic of detecting a theme is in MTThemeResolver class (part of JasperReports Server Community Project source). The corresponding bean, jsThemeResolver, is plugged into the system bean themeResolver (see applicationContext-themes.xml). Currently it uses the organization which the user belongs to. In JasperReports Server Community Project all users belong to the same default organization. In the commercial edition the multi-tenancy feature allows for the creation of multiple organizations. It has built-in support for each organization to have a different theme.

The customization would be to come up with your own class that has the logic required to resolve a theme based on [userIDRole|whatever], and plug it into themeResolver as a delegate instead of jsThemeResolver.

Note that once the system has resolved a theme, it stores it in the user session and uses this theme name until the session expires or the user specifically hits the login page (see JSThemeResolver for caching details).

The sequence is:

  • Check if there is theme=some_theme request parameter and use this theme
  • Check if the user session has a theme name already and use this theme
  • Resolve a theme based on logged user
  • Cache the theme in the user session (caching does not happen if current page is login page) 
Feedback