Interface RequestInterceptor

public interface RequestInterceptor

Used to intercept the requests for the ZK Loader and Update Engine. Developers usually use it to prepare the locale and time zone.

request(org.zkoss.zk.ui.Session, java.lang.Object, java.lang.Object) is called at very early stage, even before setting the locale for the request. Thus, you can configure the locale as follows:
sess.setAttribute(Attributes.PREFERRED_LOCALE, myLocale);

By default, the locale is decided by the browser's preference. However, you may want to store the previous locale in the cookie if your application is HTTP. Another example, you may want to retrieve the locale from the database where your application stores user's preferences.

Similarly, you can configure the time zone (that is used by some components, such as Datebox) as follows:
sess.setAttribute(Attributes.PREFERRED_TIME_ZONE, myLocale);

How this interface is used.

  1. First, you specify a class that implements this interface in WEB-INF/zk.xml as a listener. Then, an instance of the specified class is created.
  2. Each time ZK Loader or ZK Update Engine receives a request, it first invoke request(org.zkoss.zk.ui.Session, java.lang.Object, java.lang.Object) against the instance created in the previous step.


Differences to URIInterceptor

URIInterceptor is called when retrieving a page definition from an URI (PageDefinitions.getPageDefinition(org.zkoss.zk.ui.WebApp, org.zkoss.util.resource.Locator, java.lang.String)). It may or may not be caused by a client request. On the other hand, RequestInterceptor is called when ZK Loader or ZK Update Engine is receiving a client request.

See Also:

Method Summary
 void request(Session sess, java.lang.Object request, java.lang.Object response)
          Called before a request is processed by ZK Loader or ZK Update Engine.

Method Detail


void request(Session sess,
             java.lang.Object request,
             java.lang.Object response)
Called before a request is processed by ZK Loader or ZK Update Engine.

sess - the session (never null)
request - the request (never null). It is javax.servlet.http.HttpServletRequest, if the application is HTTP based. A common use is to look for the cookies.
response - the response (never null). It is javax.servlet.http.HttpServletResponse, if the application is HTTP based. A common use is to store the cookies.

Copyright © 2005-2011 Potix Corporation. All Rights Reserved. Logo