From Documentation

Jump to: navigation, search


The user could switch to any registered themes by setting a cookie or a library property.

Standard theme resolution checks the theme settings in the following order.

  1. Cookies
  2. Library property
  3. Theme priority

Dynamically switching themes using Cookies

Themes.setTheme(Executions.getCurrent(), "custom");

Internally, CookieThemeResolver provides this functionality.

Dynamically switching themes using Library Property

Library property could be used to assign a preferred theme when the current theme setting could not be obtained from Cookies.


Library.setProperty("org.zkoss.theme.preferred", "custom");

Declaratively: in (WEB-INF/zk.xml)


Theme of the last resort

If the previous two check points do not yield any result, the theme with the highest priority would be chosen. Theme priorities are usually assigned using the theme registration as well, but could also be changed dynamically.

Please refer to Themes for its family of register() methods.

Customize the Theme Resolution Process

Web developers could also add other ways for setting the current theme by writing a custom ThemeResolver'.

If you would like to communicate theme name via session instead, you would create a class like the following:

package foo;

public class SessionThemeResolver implements ThemeResolver {
    public String getTheme(HttpServletRequest request) {
        Session sess = request.getSession();
        if (sess != null) {
            return sess.getAttribute("mytheme");

    public void setTheme(HttpServletRequest request, HttpServletResponse response, String themeName) {
        Session sess = request.getSession();
        if (sess != null) {
            sess.setAttribute("mytheme", themeName);

and configure the custom ThemeResolver in WEB-INF/zk.xml.


To access the current theme resolver, please refer to ThemeFns.getThemeResolver() and ThemeFns.setThemeResolver(ThemeRegistry).

You got stuck here?
Let us know how we can improve this page
For specific questions please use the forum