From Documentation

Jump to: navigation, search







Contents


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");
Executions.sendRedirect();

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.

Programmatically:

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

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

<library-property>
    <name>org.zkoss.theme.preferred</name>
    <value>breeze</value>
</library-property>

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 {
    @Override
    public String getTheme(HttpServletRequest request) {
        Session sess = request.getSession();
        if (sess != null) {
            return sess.getAttribute("mytheme");
        }
    }

    @Override
    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.

<zk>
    <desktop-config>
        <theme-resolver-class>foo.SessionThemeResolver</theme-resolver-class>
    </desktop-config>
</zk>

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