The org.zkoss.zk.ui.sys.SEORenderer interface"

From Documentation
m
m
Line 6: Line 6:
 
A listener could implement <javadoc type="interface">org.zkoss.zk.ui.sys.SEORenderer</javadoc> to generate application-specific SEO content. The SEO content could be anything. It is visible to the search engine (for indexing), but it is not visible to the end users<ref>The SEO content will be replaced with the content of ZK components after the page has been rendered.</ref>
 
A listener could implement <javadoc type="interface">org.zkoss.zk.ui.sys.SEORenderer</javadoc> to generate application-specific SEO content. The SEO content could be anything. It is visible to the search engine (for indexing), but it is not visible to the end users<ref>The SEO content will be replaced with the content of ZK components after the page has been rendered.</ref>
  
Notice that the class must implement <javadoc type="interface">org.zkoss.zk.ui.sys.SEORenderer</javadoc>.  <javadoc type="interface" method="render(org.zkoss.zk.ui.Page, java.io.Writer)">org.zkoss.zk.ui.sys.SEORenderer</javadoc> will be invoked each time the main page of a desktop has been rendered and sent to the client<ref>It also means it won't be called in AU requests.</ref>.
+
Once registered, <javadoc type="interface" method="render(org.zkoss.zk.ui.Page, java.io.Writer)">org.zkoss.zk.ui.sys.SEORenderer</javadoc> will be invoked each time the main page of a desktop has been rendered and sent to the client<ref>It also means it won't be called in AU requests.</ref>.
  
For example, assume you have an implementation called <code>foo.MySEORenderer</code>, then
+
For example, assume you have an implementation called <code>foo.MySEORenderer</code>, then you could specify it in <tt>WEB-INF/zk.xml</tt>
  
 
<source lang="xml">
 
<source lang="xml">
 
<!-- in WEB-INF/zk.xml -->
 
<!-- in WEB-INF/zk.xml -->
<preference>
+
<listener>
     <name>org.zkoss.zk.ui.sys.SEORenderer.class</name>
+
     <listener-class>foo.MySEORenderer</listener-class>
    <value>foo.MySEORenderer</value>
+
</listener>
</preference>
 
 
</source>
 
</source>
  
Line 31: Line 30:
 
}
 
}
 
</source>
 
</source>
 +
 +
In additions to SEO content, you could also generate the JavaScript code. For example, you could implement a SEORenderer listener to generate a snippet of JavaScript code that will be embedded into every pages.
  
 
Notice that, if specified, this class will be instantiated and invoked even if [[ZK Configuration Reference/zk.xml/The system-config Element/The crawlable Element|the crawlable option]] is not enabled.
 
Notice that, if specified, this class will be instantiated and invoked even if [[ZK Configuration Reference/zk.xml/The system-config Element/The crawlable Element|the crawlable option]] is not enabled.

Revision as of 06:33, 20 April 2011


DocumentationZK Configuration Referencezk.xmlThe listener ElementThe org.zkoss.zk.ui.sys.SEORenderer interface
The org.zkoss.zk.ui.sys.SEORenderer interface


Listener:

org.zkoss.zk.ui.sys.SEORenderer

A listener could implement SEORenderer to generate application-specific SEO content. The SEO content could be anything. It is visible to the search engine (for indexing), but it is not visible to the end users[1]

Once registered, SEORenderer.render(Page, Writer) will be invoked each time the main page of a desktop has been rendered and sent to the client[2].

For example, assume you have an implementation called foo.MySEORenderer, then you could specify it in WEB-INF/zk.xml

<!-- in WEB-INF/zk.xml -->
<listener>
    <listener-class>foo.MySEORenderer</listener-class>
</listener>

You could generate anything that you'd like the search engine to index in SEORenderer.render(Page, Writer):

package foo;
import org.zkoss.zk.ui.sys.SEORenderer;
import org.zkoss.zk.ui.Page;
public class MySEORenderer implements SEORenderer {
    public void render(Page page, java.io.Writer out)
    throws java.io.IOException {
        out.write("<a href=\"whatever\">whatever</a>");
    }
}

In additions to SEO content, you could also generate the JavaScript code. For example, you could implement a SEORenderer listener to generate a snippet of JavaScript code that will be embedded into every pages.

Notice that, if specified, this class will be instantiated and invoked even if the crawlable option is not enabled.

Real Example

You can also take a look at the ZK's blog about another approach to SEO in ZK Applications.


  1. The SEO content will be replaced with the content of ZK components after the page has been rendered.
  2. It also means it won't be called in AU requests.

Version History

Last Update : 2011/04/20


Version Date Content
5.0.7 April 2011 Renderer could be specified as a listener.



Last Update : 2011/04/20

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.