In addition to high-level resource classes described in the section called “Referencing Resources”, IT Mill Toolkit provides low-level facilities
for retrieving the URI and other parameters of HTTP requests. In the
following, we will look into low-level interfaces for handling URIs and
parameters to provide resources and functionalities.
Notice that using URI or parameter handlers to create "pages" is not
meaningful in IT Mill Toolkit or in AJAX applications generally. See the section called “Special Characteristics of AJAX Applications” for reasons.
The URI parameter for the application is useful mainly for two purposes:
for providing some special functionality according to the URI or for
providing dynamic content. Dynamic content can also be provided with
StreamResource.
You can retrieve the URI for the HTTP request made for your
application by implementing the
com.itmill.toolkit.terminal.URIHandler
interface. The handler class needs to be registered in the main
window object of your application with
addURIHandler() method. You then get the
URI by implementing the handleURI()
method. The method gets two parameters: a context and a URI
relative to the context. The context is the base URI for your
application.
public void init() {
final Window main = new Window("Hello window");
setMainWindow(main);
URIHandler uriHandler = new URIHandler() {
public DownloadStream handleURI(URL context, String relativeUri) {
// Do something here
System.out.println("handleURI=" + relativeUri);
return null; // Should be null unless providing dynamic data.
}
};
main.addURIHandler(uriHandler);
}
The URI handler method should return null, unless
you wish to provide dynamic content with the call.
Caution
In IT Mill Toolkit 4 and in some other versions, the
handleURI() is called also for AJAX
requests after the page is loaded. The proper URI is passed
in the first call during the page load, but subsequent calls
have "UIDL/" in the relative path. You can
usually filter the subsequent calls out by ignoring them if
the relative path is "UIDL/".
-- Updating this section for Toolkit Release 5 is unfinished --
You can retrieve the parameters passed to your application by
implementing the
com.itmill.toolkit.terminal.ParameterHandler
interface. The handler class needs to be registered in the main
window object of your application with
addParameterHandler() method. You then
get the parameters in the
handleParameters() method. The
parameters are passes as a map from string key to a vector of
string values.
The parameter handler is not called if there are no parameters. Parameter
handler is called after the URI handler.
Caution
In IT Mill Toolkit 4 and in some other versions, the
handleParameters() is called also
for AJAX requests after the page is loaded. The proper
parameters are passed in the first call during the page load,
but subsequent calls are given a parameter map with only a
repaintAll parameter. You can usually
filter the subsequent calls out by ignoring them if they
contain the repaintAll key.
| |