Pages are the heart of web applications. In Click, Pages encapsulate the processing of HTML requests and the rendering of HTML responses. This chapter discusses Click pages in detail.
In Click, a logical page is composed of a Java class and a Velocity template, with these components being defined in page elements of the click.xml file:
<page path="search.htm
" classname="com.mycorp.page.Search"/>
The path attribute specifies the location of the page Velocity template, and the classname attribute specifies the page Java class name. If you use the Freemarker template engine instead of Velocity, the setup is the same.
The template path must have an .htm
extension which
is specified in web.xml to route
*.htm requests to the ClickServlet
. Please note that
currently Click only accepts .htm
requests, and cannot be
mapped to a different extension in web.xml
.
If you use JSP pages for rendering the .jsp
extension
must be used. For example:
<page path="search.jsp
" classname="com.mycorp.page.Search"/>
At runtime Click automatically converts the page path from
.jsp
to .htm
and back, so there is no
need to map the .jsp
extension in web.xml
.
All custom Click pages must subclass the Page base class. The Page class and its associated companion classes, Context and Control, are depicted in the figure below.
The Page class provides a model attribute which is used to hold all the objects that are rendered in the page's Velocity template. The model may also contain Control objects, which provide user interface controls on the Page.
Pages also have an associated Context object which references all the javax.servlet objects associated with the request. When programming in Click you use the Context object to access HttpServletRequest attributes, parameters and the HttpSession object.