Interface RequestInterceptor
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.
- 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.
- 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.
Note:
- Unlike
ExecutionInitand others listeners, the same instance ofRequestInterceptoris used for the whole application. Thus, you have to make sure it can be accessed concurrently.
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.
- Author:
- tomyeh
- See Also:
-
Method Summary
-
Method Details
-
request
Called before a request is processed by ZK Loader or ZK Update Engine.- Parameters:
sess- the session (never null)request- the request (never null). It is jakarta.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 jakarta.servlet.http.HttpServletResponse, if the application is HTTP based. A common use is to store the cookies.
-