ZK Filter

From Documentation
Revision as of 17:36, 27 November 2010 by Tomyeh (talk | contribs) (Created page with 'If you prefer to ''Ajax''-ize a dynamically generated HTML page (e.g., the output of a Velocity Servlet), you could use ZK Filter to process the generated page. Once the content …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

If you prefer to Ajax-ize a dynamically generated HTML page (e.g., the output of a Velocity Servlet), you could use ZK Filter to process the generated page. Once the content is processed by ZK Filter, the output is considered as a ZUML document. Thus, please make sure the output is a valid ZUML document, such as it must be a valid XML.

To enable ZK Filter, you have to configure WEB-INF/web.xml, as shown below.

<filter>
    <filter-name>zkFilter</filter-name>
    <filter-class>org.zkoss.zk.ui.http.DHtmlLayoutFilter</filter-class>
    <init-param>
        <param-name>extension</param-name>
        <param-value>html</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>zkFilter</filter-name>
    <url-pattern>/my/dyna.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>zkFilter</filter-name>
    <url-pattern>/my/dyna/*</url-pattern>
</filter-mapping>

where url-pattern is the servlets that you would like to convert HTML tags into ZK components (the XHTML component set).

The extension parameter (init-param) defines the language of the dynamical output. By default, it is html, since most of legacy servlet generates a HTML document. If it is xul/html, you could specify zul as the extension.


Notice if the extension is html and the output is HTML, it means each HTML tag will be converted to a XHTML component. It is convenient if you want to manipulate them dynamically. However, it costs more memory since ZK has to maintain the states of each HTML tags. Thus, it is suggested to use the native namespace for the portion whose content won't be changed dynamically.

Notice that, if you want to filter the output from include and/or forward, remember to specify the dispatcher element with REQUEST and/or INCLUDE. Consult the Java Servlet Specification for details. For example,

<filter-mapping>
    <filter-name>zkFilter</filter-name>
    <url-pattern>/my/dyna/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>