<html><head> | |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | |
<title>Chapter 2. Pages</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.0"><link rel="home" href="index.html" title="Apache Click"><link rel="up" href="index.html" title="Apache Click"><link rel="prev" href="ch01s07.html" title="1.7. Advanced Form Example"><link rel="next" href="ch02s02.html" title="2.2. Execution"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. Pages</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch01s07.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch02s02.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter 2. Pages"><div class="titlepage"><div><div><h2 class="title"><a name="chapter-pages"></a>Chapter 2. Pages</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="ch02.html#classes">2.1. Classes</a></span></dt><dt><span class="sect1"><a href="ch02s02.html">2.2. Execution</a></span></dt><dt><span class="sect1"><a href="ch02s03.html">2.3. Request Parameter Auto Binding</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02s03.html#customizing-auto-binding">2.3.1. Customizing Auto Binding</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02s04.html">2.4. Security</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02s04.html#applications-authentication">2.4.1. Application Authentication</a></span></dt><dt><span class="sect2"><a href="ch02s04.html#container-authentication">2.4.2. Container Authentication</a></span></dt><dt><span class="sect2"><a href="ch02s04.html#container-access-control">2.4.3. Container Access Control</a></span></dt><dt><span class="sect2"><a href="ch02s04.html#logging-out">2.4.4. Logging Out</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02s05.html">2.5. Page Navigation</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02s05.html#forward">2.5.1. Forward</a></span></dt><dd><dl><dt><span class="sect3"><a href="ch02s05.html#forward-parameter-passing">2.5.1.1. Forward Parameter Passing</a></span></dt><dt><span class="sect3"><a href="ch02s05.html#page-forwarding">2.5.1.2. Page Forwarding</a></span></dt></dl></dd><dt><span class="sect2"><a href="ch02s05.html#template-path">2.5.2. Template Path</a></span></dt><dt><span class="sect2"><a href="ch02s05.html#redirect">2.5.3. Redirect</a></span></dt><dd><dl><dt><span class="sect3"><a href="ch02s05.html#redirect-parameter-passing">2.5.3.1. Redirect Parameter Passing</a></span></dt><dt><span class="sect3"><a href="ch02s05.html#post-redirect">2.5.3.2. Post Redirect</a></span></dt></dl></dd></dl></dd><dt><span class="sect1"><a href="ch02s06.html">2.6. Page Templating</a></span></dt><dt><span class="sect1"><a href="ch02s07.html">2.7. Page Actions</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02s07.html#page-action-execution">2.7.1. Page Action Execution</a></span></dt><dt><span class="sect2"><a href="ch02s07.html#page-action-result">2.7.2. ActionResult</a></span></dt><dt><span class="sect2"><a href="ch02s07.html#page-action-example">2.7.3. Page Action Example</a></span></dt><dt><span class="sect2"><a href="ch02s07.html#page-action-accessing-request-parameters">2.7.4. Accessing Request Parameters</a></span></dt><dt><span class="sect2"><a href="ch02s07.html#page-action-set-response-headers">2.7.5. Set response headers and status code</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02s08.html">2.8. Direct Rendering</a></span></dt><dt><span class="sect1"><a href="ch02s09.html">2.9. Stateful Pages</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02s09.html#page-creation">2.9.1. Page Creation</a></span></dt><dt><span class="sect2"><a href="ch02s09.html#page-execution">2.9.2. Page Execution</a></span></dt><dt><span class="sect2"><a href="ch02s09.html#page-destruction">2.9.3. Page Destruction</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02s10.html">2.10. Error Handling</a></span></dt><dt><span class="sect1"><a href="ch02s11.html">2.11. Page Not Found</a></span></dt><dt><span class="sect1"><a href="ch02s12.html">2.12. Page Message Properties</a></span></dt><dt><span class="sect1"><a href="ch02s13.html">2.13. Page HEAD Elements</a></span></dt></dl></div><p>Pages are the heart of web applications. In Apache Click, Pages encapsulate | |
the processing of HTML requests and the rendering of HTML responses. | |
This chapter discusses Apache Click pages in detail. | |
</p><p>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 | |
<a class="link" href="ch05s02.html" title="5.2. Application Configuration">click.xml</a> | |
file: | |
</p><div class="literallayout"><p><page path="<code class="varname">search.htm</code>" classname="<span class="token">com.mycorp.page.Search</span>"/></p></div><p>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. | |
</p><p>The template path should have an <code class="varname">.htm</code> extension which | |
is specified in <a class="link" href="ch05.html#servlet-configuration" title="5.1. Servlet Configuration">web.xml</a> to route | |
*.htm requests to the <code class="classname">ClickServlet</code>. | |
</p><p>Please note if you want Click to process templates with a different | |
extension e.g. <code class="varname">.xml</code>, you need to implement the method | |
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/service/ConfigService.html#isTemplate(java.lang.String)" target="_blank">isTemplate(String path)</a> | |
and specify the extra extensions. The simplest way is to subclass | |
<code class="classname">XmlConfigService</code> and override the default implementation | |
as described <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/service/XmlConfigService.html#isTemplate(java.lang.String)" target="_blank">here</a>. | |
Also remember to map the new extensions in <code class="filename">web.xml</code>. | |
</p><p>If you use JSP pages for rendering, the <code class="varname">.jsp</code> extension | |
must be used. For example: | |
</p><div class="literallayout"><p><page path="<code class="varname">search.jsp</code>" classname="<span class="token">com.mycorp.page.Search</span>"/></p></div><p>Please note, Click does not handle JSP requests directly, instead it forwards | |
JSP requests to the servlet container. Do not map the ClickServlet to handle | |
<code class="filename">*.jsp</code> requests in <code class="filename">web.xml</code>. Instead | |
<code class="varname">.jsp</code> templates are accessed with a <code class="varname">.htm</code> | |
extension. At runtime Click will convert the page path from | |
<code class="varname">.jsp</code> to <code class="varname">.htm</code> and back. | |
</p><div class="sect1" title="2.1. Classes"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="classes"></a>2.1. Classes</h2></div></div></div><p> All custom Click pages must subclass the | |
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html" target="_blank">Page</a> base class. | |
The Page class and its associated companion classes, Context and Control, | |
are depicted in the figure below. | |
</p><div class="figure"><a name="page-class-diagram"></a><div class="figure-contents"><span class="inlinemediaobject"><img src="images/pages/click-class-diagram.png" alt="Page Class Diagram"></span></div><p xmlns:fo="http://www.w3.org/1999/XSL/Format" class="title"><i>Figure 2.1. Page Class Diagram | |
</i></p></div><br class="figure-break"><p>The Page class provides a | |
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#model" target="_blank">model</a> | |
attribute which is used to hold all the objects that are rendered in the | |
page Velocity template. The model may also contain | |
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Control.html" target="_blank">Control</a> | |
objects, which provide user interface controls on the Page. | |
</p><p>Pages also provides access to the | |
<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Context.html" target="_blank">Context</a> | |
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. | |
</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch01s07.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch02s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1.7. Advanced Form Example </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.2. Execution</td></tr></table></div></body></html> |