Registering your Theme"

From Documentation
(Created page with "{{ZKDevelopersReferencePageHeader}} Before using a theme, it must be registered so that the system knows about its existence and where to retrieve its resources (from a jar file...")
 
m
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
Before using a theme, it must be registered so that the system knows about its existence and where to retrieve its resources (from a jar file or from a folder). <javadoc>org.zkoss.zul.theme.Themes</javadoc> provides several static methods for registering your themes.  
 
Before using a theme, it must be registered so that the system knows about its existence and where to retrieve its resources (from a jar file or from a folder). <javadoc>org.zkoss.zul.theme.Themes</javadoc> provides several static methods for registering your themes.  
  
'''Available in ZK all editions'''
 
  
 +
{{ZK All}}
 
Registration, in its simplest form, is to tell the web application about the name of the theme. It will be assumed that the theme is for desktop only, and its resources should be retrieved from a jar file. For example,
 
Registration, in its simplest form, is to tell the web application about the name of the theme. It will be assumed that the theme is for desktop only, and its resources should be retrieved from a jar file. For example,
  
Line 11: Line 11:
 
</source>
 
</source>
  
'''Available in ZK 6.5.2+ all editions'''
+
 
 +
{{versionSince|6.5.2}}
 +
{{ZK All}}
 +
 
  
 
Starting from ZK 6.5.2, theme resources could also be retrieved from a folder. To indicate that a theme is folder-based, please use <javadoc>org.zkoss.web.theme.StandardTheme.ThemeOrigin</javadoc> to specify the origin of the theme resources, like below.
 
Starting from ZK 6.5.2, theme resources could also be retrieved from a folder. To indicate that a theme is folder-based, please use <javadoc>org.zkoss.web.theme.StandardTheme.ThemeOrigin</javadoc> to specify the origin of the theme resources, like below.
Line 19: Line 22:
 
</source>
 
</source>
  
'''Available in ZK EE 6.5.2+'''
+
{{versionSince|6.5.2}}
 +
{{ZK EE}}
 +
 
  
 
In ZK EE 6.5.0+, components would appear differently when viewed on tablet devices. A custom theme could be applicable to desktop only, tablet only, or both. To signify that a theme also serves tablet devices, please attach a '''"tablet:"''' prefix in front of the theme name when registering. For example,
 
In ZK EE 6.5.0+, components would appear differently when viewed on tablet devices. A custom theme could be applicable to desktop only, tablet only, or both. To signify that a theme also serves tablet devices, please attach a '''"tablet:"''' prefix in front of the theme name when registering. For example,
Line 27: Line 32:
 
</source>
 
</source>
  
== Creating Custom Theme Registration Service ==
+
== Creating a Custom Theme Registration Service ==
  
'''Available in ZK 6.5.2+ all editions'''
+
{{versionSince|6.5.2}}
 +
{{ZK EE}}
  
<javadoc>org.zkoss.web.theme.ThemeRegistry</javadoc> defines the interface to create a repository of themes available to the web application. <javadoc>org.zkoss.zul.theme.DesktopThemeRegistry</javadoc> (for ZK CE/PE) and <javadoc>org.zkoss.zkmax.theme.ResponsiveThemeRegistry</javadoc> (for ZK EE) are the standard implementations that actually stores the registered themes.
+
<javadoc>org.zkoss.web.theme.ThemeRegistry</javadoc> defines the interface to create a repository of themes available to the web application. <javadoc>org.zkoss.zul.theme.DesktopThemeRegistry</javadoc> (for ZK CE/PE) and <javadoc>org.zkoss.zkmax.theme.ResponsiveThemeRegistry</javadoc> (for ZK EE) are the standard implementations that actually store the registered themes.
  
 
Standard theme registries would accept all theme registrations. Duplicate registration would update theme information. Registered themes are available to all users. (For ZK EE, desktop clients would only have desktop themes available, and tablet clients would only have tablet themes available.) If you would like to modify any of these behaviors, please provide a custom ThemeRegistry.  
 
Standard theme registries would accept all theme registrations. Duplicate registration would update theme information. Registered themes are available to all users. (For ZK EE, desktop clients would only have desktop themes available, and tablet clients would only have tablet themes available.) If you would like to modify any of these behaviors, please provide a custom ThemeRegistry.  

Latest revision as of 09:42, 31 January 2024

Before using a theme, it must be registered so that the system knows about its existence and where to retrieve its resources (from a jar file or from a folder). Themes provides several static methods for registering your themes.


  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ce-pe-ee.png

Registration, in its simplest form, is to tell the web application about the name of the theme. It will be assumed that the theme is for desktop only, and its resources should be retrieved from a jar file. For example,

Themes.register("custom");


Since 6.5.2

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ce-pe-ee.png


Starting from ZK 6.5.2, theme resources could also be retrieved from a folder. To indicate that a theme is folder-based, please use StandardTheme.ThemeOrigin to specify the origin of the theme resources, like below.

Themes.register("custom", ThemeOrigin.FOLDER);

Since 6.5.2

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png


In ZK EE 6.5.0+, components would appear differently when viewed on tablet devices. A custom theme could be applicable to desktop only, tablet only, or both. To signify that a theme also serves tablet devices, please attach a "tablet:" prefix in front of the theme name when registering. For example,

Themes.register("tablet:custom");

Creating a Custom Theme Registration Service

Since 6.5.2

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png

ThemeRegistry defines the interface to create a repository of themes available to the web application. DesktopThemeRegistry (for ZK CE/PE) and ResponsiveThemeRegistry (for ZK EE) are the standard implementations that actually store the registered themes.

Standard theme registries would accept all theme registrations. Duplicate registration would update theme information. Registered themes are available to all users. (For ZK EE, desktop clients would only have desktop themes available, and tablet clients would only have tablet themes available.) If you would like to modify any of these behaviors, please provide a custom ThemeRegistry.

For example, a custom ThemeRegistry could be created by implementing ThemeRegistry interface directly, or extending one of the standard implementations, depending on the ZK edition you are using.

package foo;

public class CustomThemeRegistry implements ThemeRegistry {
    ...
}

And then, configure the custom ThemeRegistry in WEB-INF/zk.xml.

<zk>
	<desktop-config>
		<theme-registry-class>foo.CustomThemeRegistry</theme-registry-class>
	</desktop-config>
</zk>

To access the current theme registry, please refer to ThemeFns.getThemeRegistry() and ThemeFns.setThemeRegistry(ThemeRegistry).