You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by ta...@apache.org on 2010/02/12 00:36:29 UTC
svn commit: r909177 [2/11] - in
/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide:
./ css/ images/ images/best-practices/ images/callouts/ images/colorsvg/
images/configuration/ images/controls/ images/introduction/ images/pa...
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch01s07.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch01s07.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch01s07.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch01s07.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,127 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>1.7. Advanced Form Example</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="ch01.html" title="Chapter 1. Introduction to Apache Click"><link rel="prev" href="ch01s06.html" title="1.6. Simple Form Example"><link rel="next" href="ch02.html" title="Chapter 2. Pages"></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">1.7. Advanced Form Example</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch01s06.html">Prev</a> </td><th width="60%" align="center">Chapter 1. Introduction to Apache Click</th><td width="20%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr></table><hr></div><div
class="sect1" title="1.7. Advanced Form Example"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="advanced-form"></a>1.7. Advanced Form Example</h2></div></div></div><p>The <code class="classname">AdvancedForm</code> page below provides a more
+ advanced demonstration of using Form, Field and FielsSet controls.
+ </p><p>First we have an <code class="classname">AdvancedForm</code> class which
+ setups up a <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/Form.html" target="_blank">Form</a>
+ in its constructor. The form's investment
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/Select.html" target="_blank">Select</a>
+ list is populated in the page's <code class="methodname">onInit()</code> method. At
+ this point any page dependencies such as the CustomerService should be
+ available.
+ </p><p>Note in this example the page's public <code class="varname">form</code> field
+ is automatically added to its list of controls. The <code class="varname">msg</code>
+ field is added to the page's model.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> AdvancedForm <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pun">@Bindable</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">protected</span> Form form = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Form();
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pun">@Bindable</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">protected</span> String msg;
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">private</span> Select investmentSelect = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Select(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"investment"</span>);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// -------------------------------------------------------- Constructor</span>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> AdvancedForm() {
+ FieldSet fieldSet = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> FieldSet(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"Customer"</span>);
+ form.add(fieldSet);
+
+ TextField nameField = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> TextField(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"name"</span>, true);
+ nameField.setMinLength(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="lit">5</span>);
+ nameField.setFocus(true);
+ fieldSet.add(nameField);
+
+ fieldSet.add(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> EmailField(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"email"</span>, true));
+
+ fieldSet.add(investmentSelect);
+
+ fieldSet.add(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> DateField(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"dateJoined"</span>, true));
+ fieldSet.add(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Checkbox(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"active"</span>));
+
+ form.add(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Submit(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"ok"</span>, <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">" OK "</span>, <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">this</span>, <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"onOkClicked"</span>));
+ form.add(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Submit(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"cancel"</span>, <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">this</span>, <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"onCancelClicked"</span>));
+ }
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// ----------------------------------------------------- Event Handlers</span>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onInit()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pun">@Override</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">void</span> onInit() {
+ CustomerService customerService = getCustomerService();
+ investmentSelect.add(Option.EMPTY_OPTION);
+ investmentSelect.addAll(customerService.getInvestmentCatetories());
+ }
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * Handle the OK button click event.
+ *
+ * @return true
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onOkClicked() {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (form.isValid()) {
+ Customer customer = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Customer();
+ form.copyTo(customer);
+
+ getCustomerService().saveCustomer(customer);
+
+ form.clearValues();
+
+ msg = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"A new customer record has been created."</span>;
+ }
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> true;
+ }
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * Handle the Cancel button click event.
+ *
+ * @return false
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onCancelClicked() {
+ setRedirect(HomePage.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+ }
+}</pre><p>Next we have the AdvancedForm template
+ <code class="filename">advanced-form.htm</code>. The Click application automatically
+ associates the <code class="filename">advanced-form.htm</code> template with the
+ <code class="classname">AdvancedForm</code> class.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><html></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><head></span>
+ <code class="varname">$headElements</code>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><body></span>
+
+ <span class="command"><strong>#if</strong></span> (<code class="varname">$msg</code>)
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><div</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">id</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"msgDiv"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">></span> <code class="varname">$msg</code> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></div></span>
+ <span class="command"><strong>#end</strong></span>
+
+ <code class="varname">$form</code>
+
+ <code class="varname">$headElements</code>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></body></span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></html></span></pre><p>When the AdvancedForm page is first requested the
+ <code class="varname">$form</code> object will automatically render itself as:
+ </p><div class="figure"><a name="advanced-form-image"></a><div class="figure-contents"><div class="mediaobject"><img src="images/introduction/advanced-form.png" alt="Advanced Form"></div></div><p xmlns:fo="http://www.w3.org/1999/XSL/Format" class="title"><i>Figure 1.7. Advanced Form</i></p></div><br class="figure-break"><p>In this example when the OK button is clicked the
+ <code class="methodname">onOkClicked()</code> method is invoked. If the form is
+ valid a new customer object is created and the forms field values are copied
+ to the new object using the Form
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/Form.html#copyTo(java.lang.Object)" target="_blank">copyTo()</a>
+ method. The customer object is then saved, the form's field values are
+ cleared and an info message is presented to the user.
+ </p><p>If the user clicks on the Cancel button the request is redirected to
+ the applications HomePage.
+ </p><div class="sect2" title="1.7.1. Form Layout"><div class="titlepage"><div><div><h3 class="title"><a name="form-layout"></a>1.7.1. Form Layout</h3></div></div></div><p>In the example above the Form control automatically renders the form
+ and the fields HTML markup. This is a great feature for quickly building
+ screens, and the form control provides a number of layout options. See the
+ Click Examples for an interactive
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://www.avoka.com/click-examples/form/form-properties.htm" target="_blank">Form Properties demo</a>.
+ </p><p>For fine grained page design you can specifically layout form and
+ fields in your page template. See the
+ <a class="link" href="ch03s07.html#template-layout" title="3.7.1. Template layout">Template Layout</a> section and
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/control/Form.html#form-layout" target="_blank">Form</a>
+ Javadoc for more details.
+ </p><p>An alternative to page template design is using a programmatic
+ approach. See <a class="link" href="ch03s07.html#programmatic-layout" title="3.7.2. Programmatic layout">Programmatic Layout</a>
+ for more details.
+ </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch01s06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch01.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1.6. Simple Form Example </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 2. Pages</td></tr></table></div></body></html>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch01s07.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,44 @@
+<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="ch02s
04.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. Direct Rendering</a></span></dt><dt><span class="sect1"><a href="ch02s08.html">2.8. Stateful Pages</a></span></dt><dd><dl><dt><span class="sect2"><a href="ch02s08.html#page-creation">2.8.1. Page Creation</a></span></dt><dt><span class="sect2"><a href="ch02s08.html#page-execution">2.8.2. Page Execution</a></span></dt><dt><span class="sect2"><a href="ch02s08.html#page-destruction">2.8.3. Page Destruction</a></span></dt></dl></dd><dt><span class="sect1"><a href="ch02s09.html">2.9. Error Handling</a></span></dt><dt><span class="sect1"><a href="ch02s10.html">2.10. Page Not Found</a></span></dt><dt><span class="sect1"><a href="ch02s11.html">2.11. Page Message Properties</a></span></dt><dt><span class="sect1"><a href="ch02s12.html">2.12. 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="ch04s02.html" title="4.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="ch04.html#servlet-configuration" title="4.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>At runtime Click automatically converts the page path from
+ <code class="varname">.jsp</code> to <code class="varname">.htm</code> and back, so there is no
+ need to map the <code class="varname">.jsp</code> extension in <code class="filename">web.xml</code>.
+ </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's 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 have an associated
+ <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>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s02.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s02.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s02.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s02.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,94 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>2.2. Execution</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="ch02.html" title="Chapter 2. Pages"><link rel="prev" href="ch02.html" title="Chapter 2. Pages"><link rel="next" href="ch02s03.html" title="2.3. Request Parameter Auto Binding"></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">2.2. Execution</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Pages</th><td width="20%" align="right"> <a accesskey="n" href="ch02s03.html">Next</a></td></tr></table><hr></div><div class="sect1" title="2.2. Execution"><div class="titl
epage"><div><div><h2 class="title" style="clear: both"><a name="execution"></a>2.2. Execution</h2></div></div></div><p>The Page class provide a number of empty handler methods which
+ subclasses can override to provide functionality:
+ </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onSecurityCheck()" target="_blank">onSecurityCheck()</a>
+ </p></li><li class="listitem"><p>
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onInit()" target="_blank">onInit()</a>
+ </p></li><li class="listitem"><p>
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onGet()" target="_blank">onGet()</a>
+ </p></li><li class="listitem"><p>
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onPost()" target="_blank">onPost()</a>
+ </p></li><li class="listitem"><p>
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onRender()" target="_blank">onRender()</a>
+ </p></li><li class="listitem"><p>
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onDestroy()" target="_blank">onDestroy()</a>
+ </p></li></ul></div><p>The ClickServlet relies on instantiating Pages using a public no
+ arguments constructor, so when you create Page subclasses you must ensure
+ you don't add an incompatible constructor. The GET request execution sequence
+ for Pages is summarized below in the Figure 2.
+ </p><div class="figure"><a name="get-sequence-diagram"></a><div class="figure-contents"><span class="inlinemediaobject"><img src="images/pages/get-sequence-diagram.png" alt="GET Request Sequence Diagram"></span></div><p xmlns:fo="http://www.w3.org/1999/XSL/Format" class="title"><i>Figure 2.2. GET Request Sequence Diagram
+ </i></p></div><br class="figure-break"><p>Stepping through this GET request sequence, a new Page instance is
+ created and the attributes for the Page are set (context, format, headers,
+ path). Next, request parameter values are bound to any matching public
+ Page fields.
+ </p><p>Then the <code class="methodname">onSecurityCheck()</code> handler is executed.
+ This method can be used to ensure the user is authorized to access the page,
+ and if necessary abort any further processing.
+ </p><p>The next method invoked is <code class="methodname">onInit()</code>, this is
+ where you place any post constructor initialization code.
+ <code class="methodname">onInit()</code> is the ideal place to create controls such
+ as Forms, Fields and Tables. As illustrated by the diagram, after a Page's
+ <code class="methodname">onInit()</code> is called, each Control, available at that
+ stage, will have their <code class="methodname">onInit()</code> method called.
+ </p><p>
+ The next step is the processing of the Page's
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#controls" target="_blank">controls</a>.
+ The ClickServlet gets the list of Controls from the page and then iterates
+ through the list calling <code class="methodname">onProcess()</code>. If any of the
+ Control's <code class="methodname">onProcess()</code> methods return false,
+ processing of subsequent controls and the Page's <code class="methodname">onGet()</code>
+ method is aborted.
+ </p><p>If everything is executing normally the Page's
+ <code class="methodname">onGet()</code> method is now called.
+ </p><p>The next step is rendering the page template to generate the displayed
+ HTML. The ClickServlet gets the model (<code class="classname">Map</code>) from the
+ Page then adds the following objects to the model:
+ </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>any public Page fields using the fields name</p></li><li class="listitem"><p>context - the Servlet context path, e.g. /mycorp</p></li><li class="listitem"><p>format - the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/Format.html" target="_blank">Format</a>
+ object for formatting the display of objects.
+ </p></li><li class="listitem"><p>headElements - the HEAD <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/element/Element.html" target="_blank">elements</a>,
+ excluding JavaScript, to include in the page header. Please see
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/PageImports.html" target="_blank">PageImports</a>
+ for more details.
+ </p></li><li class="listitem"><p>jsElements - the JavaScript imports and script blocks to
+ include in the pages footer. Please see
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/PageImports.html" target="_blank">PageImports</a>
+ for more details.
+ </p></li><li class="listitem"><p>messages - the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/MessagesMap.html" target="_blank">MessagesMap</a>
+ adaptor for the Page
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#getMessage(java.lang.String)" target="_blank">getMessage()</a>
+ method
+ </p></li><li class="listitem"><p>path - the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#path" target="_blank">path</a> of
+ the page template to render
+ </p></li><li class="listitem"><p>request - the pages
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletRequest.html" target="_blank">HttpServletRequest</a>
+ object
+ </p></li><li class="listitem"><p>response - the pages
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletResponse.html" target="_blank">HttpServletResponse</a>
+ object
+ </p></li><li class="listitem"><p>session - the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/SessionMap.html" target="_blank">SessionMap</a>
+ adaptor for the users
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpSession.html" target="_blank">HttpSession</a>
+ </p></li></ul></div><p>It then merges the template with the page model and writes out results
+ to the HttpServletResponse. When the model is being merged with the template,
+ any Controls in the model may be rendered using their
+ <code class="methodname">toString()</code> method.
+ </p><p>The final step in this sequence is invoking each control's
+ <code class="methodname">onDestroy()</code> method and lastly invoke the Page's
+ <code class="methodname">onDestroy()</code> method. This method can be used to
+ clean up resource associated with the Control or Page before it is garbage
+ collected. The <code class="methodname">onDestroy()</code> method is guaranteed to
+ be called even if an exception occurs in the previous steps.
+ </p><p>The execution sequence for POST requests is almost identical, except
+ the <code class="methodname">onPost()</code> method is invoked instead on
+ <code class="methodname">onGet()</code>. See the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../../images/post-sequence-diagram.png" target="_blank">POST Request Sequence Diagram</a>.
+ </p><p>Another view on the execution flow of Pages is illustrated in the
+ Activity diagram below.
+ </p><div class="figure"><a name="activity-diagram"></a><div class="figure-contents"><span class="inlinemediaobject"><img src="images/pages/activity-diagram-small.png" alt="Page Execution Activity Diagram"></span></div><p xmlns:fo="http://www.w3.org/1999/XSL/Format" class="title"><i>Figure 2.3. Page Execution Activity Diagram
+ </i></p></div><br class="figure-break"></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 2. Pages </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.3. Request Parameter Auto Binding</td></tr></table></div></body></html>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s02.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s03.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s03.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s03.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s03.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,91 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>2.3. Request Parameter Auto Binding</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="ch02.html" title="Chapter 2. Pages"><link rel="prev" href="ch02s02.html" title="2.2. Execution"><link rel="next" href="ch02s04.html" title="2.4. Security"></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">2.3. Request Parameter Auto Binding</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s02.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Pages</th><td width="20%" align="right"> <a accesskey="n" href="ch02s04.html">Next</a></td></tr></table><hr></div><div class="sect1" title="2.3. Request
Parameter Auto Binding"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="request-param-auto-binding"></a>2.3. Request Parameter Auto Binding</h2></div></div></div><p>Click will automatically bind any request parameter values to public
+ Page fields with the same name. You can also use the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/Bindable.html" target="_blank">Bindable</a>
+ annotation to bind private and protected Page fields. When binding these
+ values Click will also attempt to convert them to the correct type.
+ </p><p>The best way to understand this is to walk through an example. Our
+ application recieves a GET request:
+ </p><div class="literallayout"><p>http://localhost:8080/mycorp/customer-details.htm?<code class="varname">customerId</code>=<span class="symbol">7203</span></p></div><p>This request is automatically handled by our
+ <code class="classname">CustomerDetails</code> page:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">package</span> com.mycorp.page;
+
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> CustomerDetails <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pun">@Bindable</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">protected</span> Integer <code class="varname">customerId</code>;
+}</pre><p>After the CustomerDetails page has been created the
+ "<code class="varname">customerId</code>" request parameter value "<span class="symbol">7023</span>"
+ will be converted into an Integer and assigned to the public page field
+ <code class="varname">customerId</code>.
+ </p><p>Another feature of Click is that any public Page fields are
+ automatically added to the page's model before it is rendered. This will
+ make these values available in the page template for display. In our example
+ the public <code class="varname">customerId</code> field will be added to the Page
+ model and will be available for rendering in the page template.
+ </p><p>Our customer-details.htm page template contains:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><html></span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><body></span>
+
+ Customer ID: <span class="symbol">$</span><code class="varname">customerId</code>
+
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></body></span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></html></span></pre><p>After processing the request our page would be rendered as:
+ </p><div class="literallayout"><p>Customer ID: 7203</p></div><div class="sect2" title="2.3.1. Customizing Auto Binding"><div class="titlepage"><div><div><h3 class="title"><a name="customizing-auto-binding"></a>2.3.1. Customizing Auto Binding</h3></div></div></div><p>Auto binding supports the conversion of request string parameters
+ into the Java classes: Integer, Double, Boolean, Byte, Character, Short,
+ Long, Float, BigInteger, BigDecimal, String and the various Date classes.
+ </p><p>By default type conversion is performed by the
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/util/RequestTypeConverter.html" target="_blank">RequestTypeConverter</a>
+ class which is used by the ClickServlet method
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/ClickServlet.html#getTypeConverter()" target="_blank">getTypeConverter()</a>.
+ </p><p>If you need to add support for additional types, you would write your
+ own type converter class and specify it as a ClickServlet init parameter.
+ </p><p>For example if you wanted to automatically load a
+ <code class="classname">Customer</code> object from the database when a customer
+ id request parameter is specified, you could write your own type converter:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> CustomTypeConverter <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> RequestTypeConverter {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">private</span> CustomerService customerService = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> CustomerService();
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see RequestTypeConverter#convertValue(Object, Class)
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">protected</span> Object convertValue(Object value, Class toType) {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (toType == Customer.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>) {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> customerService.getCustomerForId(value);
+
+ } <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">else</span> {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">super</span>.convertValue(value, toType);
+ }
+ }
+}</pre><p>This type converter would handle the following request:
+ </p><div class="literallayout"><p>http://localhost:8080/mycorp/customer-details.htm?<code class="varname">customer</code>=<span class="symbol">7203</span></p></div><p>This request will load the <code class="varname">customer</code> object from
+ the database using "<span class="symbol">7203</span>" as the customer id value. The
+ ClickServlet would then assign this <code class="varname">customer</code> object to
+ the matching page field:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">package</span> com.mycorp.page;
+
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> CustomerDetails <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pun">@Bindable</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">protected</span> Customer <code class="varname">customer</code>;
+
+}</pre><p>To make your custom type converter available you will need to
+ add an init parameter to ClickServlet in <code class="filename">web.xml</code>. For example:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><web-app></span>
+ ...
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><servlet></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><servlet-name></span>ClickServlet<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></servlet-name></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><servlet-class></span>org.apache.click.ClickServlet<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></servlet-class></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><init-param></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><param-name></span>type-converter-class<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></param-name></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><param-value></span>com.mycorp.util.CustomTypeConverter<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></param-value></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></init-param></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><load-on-startup></span>0<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></load-on-startup></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></servlet></span>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><servlet-mapping></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><servlet-name></span>ClickServlet<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></servlet-name></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><url-pattern></span>*.htm<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></url-pattern></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></servlet-mapping></span>
+ ...
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></web-app></span></pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.2. Execution </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.4. Security</td></tr></table></div></body></html>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s03.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s04.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s04.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s04.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s04.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,80 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>2.4. Security</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="ch02.html" title="Chapter 2. Pages"><link rel="prev" href="ch02s03.html" title="2.3. Request Parameter Auto Binding"><link rel="next" href="ch02s05.html" title="2.5. Page Navigation"></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">2.4. Security</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s03.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Pages</th><td width="20%" align="right"> <a accesskey="n" href="ch02s05.html">Next</a></td></tr></table><hr></div><div class="sect1" title="2.4. Security"><div class="ti
tlepage"><div><div><h2 class="title" style="clear: both"><a name="page-security"></a>2.4. Security</h2></div></div></div><p>Pages provide an
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onSecurityCheck()" target="_blank">onSecurityCheck</a>
+ event handler which application pages can override to implement a
+ programmatic security model.
+ </p><p>Please note you generally don't need to use this capability, and where
+ possible you should use the declarative JEE security model. See the Best
+ Practices <a class="link" href="ch05.html#security" title="5.1. Security">Security</a> topic for more details.
+ </p><div class="sect2" title="2.4.1. Application Authentication"><div class="titlepage"><div><div><h3 class="title"><a name="applications-authentication"></a>2.4.1. Application Authentication</h3></div></div></div><p>Applications can use the <code class="methodname">onSecurityCheck()</code>
+ method to implement their own security model. The example class below
+ provides a base Secure page class which other pages can extend to ensure
+ the user is logged in. In this example the login page creates a session
+ when a user successfully authenticates. This Secure page then checks to
+ make sure the user has a session, otherwise the request is redirected to
+ the login page.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> Secure <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onSecurityCheck()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onSecurityCheck() {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (getContext().hasSession()) {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> true;
+
+ } <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">else</span> {
+ setRedirect(LoginPage.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+ }
+ }
+}</pre></div><div class="sect2" title="2.4.2. Container Authentication"><div class="titlepage"><div><div><h3 class="title"><a name="container-authentication"></a>2.4.2. Container Authentication</h3></div></div></div><p>Alternatively you can also use the security services provided by
+ the JEE Servlet Container. For instance to ensure users have been
+ authenticated by the Serlvet Container you could use a Secure page of:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> Secure <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onSecurityCheck()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onSecurityCheck() {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (getContext().getRequest().<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletRequest.html#getRemoteUser()" target="_blank"><code class="varname">getRemoteUser</code></a>() != null) {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> true;
+
+ } <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">else</span> {
+ setRedirect(LoginPage.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+ }
+ }
+}</pre></div><div class="sect2" title="2.4.3. Container Access Control"><div class="titlepage"><div><div><h3 class="title"><a name="container-access-control"></a>2.4.3. Container Access Control</h3></div></div></div><p>The Servlet Container also provides facilities to enforce role
+ based access control (authorization). The example below is a base page
+ to ensure only users in the "admin" role can access the page, otherwise
+ users are redirected to the login page. Application Admin pages would
+ extend this secure page to provide their functionality.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> AdminPage <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onSecurityCheck()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onSecurityCheck() {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (getContext().getRequest().<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletRequest.html#isUserInRole(java.lang.String)" target="_blank"><code class="varname">isUserInRole</code></a>(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"admin"</span>)) {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> true;
+
+ } <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">else</span> {
+ setRedirect(LoginPage.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+ }
+ }
+}</pre></div><div class="sect2" title="2.4.4. Logging Out"><div class="titlepage"><div><div><h3 class="title"><a name="logging-out"></a>2.4.4. Logging Out</h3></div></div></div><p>To logout using the application or container based security models
+ you would simply invalidate the session.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> Logout <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onInit()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">void</span> onInit() {
+ getContext().getSession().<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpSession.html#invalidate()" target="_blank"><code class="varname">invalidate</code></a>();
+ }
+}</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.3. Request Parameter Auto Binding </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.5. Page Navigation</td></tr></table></div></body></html>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s04.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s05.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s05.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s05.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s05.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,194 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>2.5. Page Navigation</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="ch02.html" title="Chapter 2. Pages"><link rel="prev" href="ch02s04.html" title="2.4. Security"><link rel="next" href="ch02s06.html" title="2.6. Page Templating"></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">2.5. Page Navigation</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s04.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Pages</th><td width="20%" align="right"> <a accesskey="n" href="ch02s06.html">Next</a></td></tr></table><hr></div><div class="sect1" title="2.5. Page Navigation"><div class="tit
lepage"><div><div><h2 class="title" style="clear: both"><a name="page-navigation"></a>2.5. Page Navigation</h2></div></div></div><p> Navigation between pages is achieved by using forwards, redirects
+ and by setting the page template path.
+ </p><div class="sect2" title="2.5.1. Forward"><div class="titlepage"><div><div><h3 class="title"><a name="forward"></a>2.5.1. Forward</h3></div></div></div><p> To forward to another page using the servlet
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/RequestDispatcher.html" target="_blank">RequestDispatcher</a>,
+ set the Page's forward property. For example to forward to a page with a
+ path <code class="varname">index.htm</code>:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onPost()
+ */</span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">void</span> onPost() {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Process form post</span>
+ ..
+
+ setForward(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"index.htm"</span>);
+}</pre><p>This will invoke a new Page class instance mapped to the path
+ <code class="varname">index.htm</code>.
+ </p><p><span class="bold"><strong>Please note</strong></span> when a request is
+ forwarded to another Page, the controls on the second page will not be
+ processed. This prevents confusion and bugs, like a form on the second page
+ trying to process a POST request from the first page.
+ </p><div class="sect3" title="2.5.1.1. Forward Parameter Passing"><div class="titlepage"><div><div><h4 class="title"><a name="forward-parameter-passing"></a>2.5.1.1. Forward Parameter Passing</h4></div></div></div><p>When you forward to another page the request parameters are
+ maintained. This is a handy way of passing through state information
+ with the request. For example you could add a customer object as a
+ request parameter which is displayed in the template of the forwarded
+ page.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onViewClick() {
+ Long id = viewLink.getValueLong();
+ Customer customer = CustomerDAO.findByPK(id);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Set the customer object as a request parameter</span>
+ getContext().setRequestAttribute(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"customer"</span>, customer);
+ setForward(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"view-customer.htm"</span>);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><p>The snippet above forwards to the page template
+ <code class="varname">view-customer.htm</code>:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><html></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><title></span>Customer Details<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></title></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><body></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><h1></span>Customer Details<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></h1></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><pre></span>
+ Full Name: <code class="varname">$customer.fullName</code>
+ Email: <code class="varname">$customer.email</code>
+ Telephone: <code class="varname">$customer.telephone</code>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></pre></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></body></span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></html></span></pre><p>Request attributes are automatically added to the Velocity Context
+ object so are available in the page template.
+ </p></div><div class="sect3" title="2.5.1.2. Page Forwarding"><div class="titlepage"><div><div><h4 class="title"><a name="page-forwarding"></a>2.5.1.2. Page Forwarding</h4></div></div></div><p>Page forwarding is another way of passing information between
+ pages. In this case you create the page to be forwarded to using the
+ Context <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Context.html#createPage(java.lang.String)" target="_blank">createPage(String)</a>
+ method and then set properties directly on the Page. Finally set this
+ page as the page to forward the request to. For example:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onEditClick() {
+ Long id = viewLink.getValueLong();
+ Customer customer = CustomerDAO.findByPK(id);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Create a new EditPage instance based on the specified path</span>
+ EditPage editPage = (EditPage) getContext().createPage(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"/edit-customer.htm"</span>);
+ editPage.setCustomer(customer);
+ setForward(editPage);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><p>When creating a page with the <code class="methodname">createPage()</code>
+ method, ensure you prefix the page path with the <code class="varname">"/"</code>
+ character.
+ </p><p>You can also specify the target page using its class as long as
+ the Page has a unique path. Using this technique the above code becomes:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onEditClick() {
+ Long id = viewLink.getValueLong();
+ Customer customer = CustomerDAO.findByPK(id);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Create a new EditPage instance based on its class</span>
+ EditPage editPage = (EditPage) getContext().createPage(EditPage.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ editPage.setCustomer(customer);
+ setForward(editPage);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><p>This Page forwarding technique is best practice as it provides you
+ with compile time safety and alleviates you from having to specify page
+ paths in your code. Please always use the Context
+ <code class="methodname">createPage()</code> methods to allow Click to inject
+ Page dependencies.
+ </p><p>Although uncommon it is possible to map more than one path to the
+ same class. In these cases invoking Context
+ <code class="methodname">createPage(Class)</code> will throw an exception, because
+ Click will not be able to determine which path to use for the Page.
+ </p></div></div><div class="sect2" title="2.5.2. Template Path"><div class="titlepage"><div><div><h3 class="title"><a name="template-path"></a>2.5.2. Template Path</h3></div></div></div><p>An alternative method of forwarding to a new page is to simply set
+ the current Page's path to the new page template to render. With this
+ approach the page template being rendered must have everything it needs
+ without having its associated Page object created. Our modified example
+ would be:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onViewClick() {
+ Long id = viewLink.getValueLong();
+ Customer customer = CustomerDAO.findByPK(id);
+
+ addModel(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"customer"</span>, customer);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Set the Page's path to a new value</span>
+ setPath(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"view-customer.htm"</span>);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><p>Note how the <code class="varname">customer</code> object is passed through to
+ the template in the Page model. This approach of using the Page model is
+ not available when you forward to another Page, as the first Page object is
+ "<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#onDestroy()" target="_blank">destroyed</a>"
+ before the second Page object is created and any model values would be lost.
+ </p></div><div class="sect2" title="2.5.3. Redirect"><div class="titlepage"><div><div><h3 class="title"><a name="redirect"></a>2.5.3. Redirect</h3></div></div></div><p>Redirects are another very useful way to navigate between pages.
+ See HttpServletResponse.
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletResponse.html#sendRedirect(java.lang.String)" target="_blank">sendRedirect</a>
+ (location) for details.
+ </p><p>The great thing about redirects are that they provide a clean URL in
+ the users browser which matches the page that they are viewing. This is
+ important for when users want to bookmark a page. The downside of
+ redirects are that they involve a communications round trip with the users
+ browser which requests the new page. Not only does this take time, it also
+ means that all the page and request information is lost.
+ </p><p>An example of a redirect to a <code class="varname">logout.htm</code> page is
+ provided below:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onLogoutClick() {
+ setRedirect(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"/logout.htm"</span>);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><p>If the redirect location begins with a <span class="symbol">"/"</span> character
+ the redirect location will be prefixed with the web applications context
+ path. For example if an application is deployed to the context
+ <code class="varname">"mycorp"</code> calling
+ <code class="methodname">setRedirect(<code class="varname">"/customer/details.htm"</code>)</code>
+ will redirect the request to: <code class="varname">"/mycorp/customer/details.htm"</code>.
+ </p><p>You can also obtain the redirect path via the target Page's class.
+ For example:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onLogoutClick() {
+ String path = getContext().getPagePath(Logout.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ setRedirect(path);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><p>Note when using this redirect method, the target Page class must have
+ a unique path.
+ </p><p>A short hand way of redirecting is to simply specify the target Page
+ class in the redirect method. For example:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onLogoutClick() {
+ setRedirect(Logout.<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span>);
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+}</pre><div class="sect3" title="2.5.3.1. Redirect Parameter Passing"><div class="titlepage"><div><div><h4 class="title"><a name="redirect-parameter-passing"></a>2.5.3.1. Redirect Parameter Passing</h4></div></div></div><p>You can pass information between redirected pages using URL
+ request parameters. The ClickServlet will encode the URL for you using
+ HttpServletResponse.<a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletResponse.html#encodeRedirectURL(java.lang.String)" target="_blank">encodeRedirectURL</a>
+ (url).
+ </p><p>In the example below a user will click on an OK button to confirm
+ a payment. The <code class="methodname">onOkClick()</code> button handler
+ processes the payment, gets the payment transaction id, and then
+ redirects to the <code class="varname">trans-complete.htm</code> page with the
+ transaction id encoded in the URL.
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> Payment <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+ ..
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">boolean</span> onOkClick() {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (form.isValid()) {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Process payment</span>
+ ..
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Get transaction id</span>
+ Long transId = OrderDAO.purchase(order);
+
+ setRedirect(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"trans-complete.htm?transId="</span> + transId);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> false;
+ }
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> true;
+ }
+}</pre><p>The Page class for the trans-complete.htm page can then get the
+ transaction id through the request parameter <code class="varname">"transId"</code>:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> TransComplete <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#onInit()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">void</span> onInit() {
+ String transId = getContext().getRequest().getParameter(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"transId"</span>);
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (transId != null) {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">// Get order details</span>
+ Order order = OrderDAO.findOrderByPK(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">new</span> Long(transId));
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">if</span> (order != null) {
+ addModel(<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"order"</span>, order);
+ }
+ }
+ }
+}</pre></div><div class="sect3" title="2.5.3.2. Post Redirect"><div class="titlepage"><div><div><h4 class="title"><a name="post-redirect"></a>2.5.3.2. Post Redirect</h4></div></div></div><p>The parameter passing example above is also an example of a Post
+ Redirect. The Post Redirect technique is a very useful method of
+ preventing users from submitting a form twice by hitting the refresh
+ button.
+ </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.4. Security </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.6. Page Templating</td></tr></table></div></body></html>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s05.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s06.html
URL: http://svn.apache.org/viewvc/click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s06.html?rev=909177&view=auto
==============================================================================
--- click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s06.html (added)
+++ click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s06.html Thu Feb 11 23:36:18 2010
@@ -0,0 +1,66 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+ <title>2.6. Page Templating</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="ch02.html" title="Chapter 2. Pages"><link rel="prev" href="ch02s05.html" title="2.5. Page Navigation"><link rel="next" href="ch02s07.html" title="2.7. Direct Rendering"></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">2.6. Page Templating</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s05.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Pages</th><td width="20%" align="right"> <a accesskey="n" href="ch02s07.html">Next</a></td></tr></table><hr></div><div class="sect1" title="2.6. Page Templating"><div cl
ass="titlepage"><div><div><h2 class="title" style="clear: both"><a name="page-templating"></a>2.6. Page Templating</h2></div></div></div><p>Click supports page templating (a.k.a. <span class="emphasis"><em>Tiles</em></span> in
+ Struts) enabling you to create a standardized look and feel for your web
+ application and greatly reducing the amount of HTML you need to maintain.
+ </p><p>To implement templating define a border template base Page which
+ content Pages should extend. The template base Page class overrides the Page
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#getTemplate()" target="_blank">getTemplate()</a>
+ method, returning the path of the border template to render. For example:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> BorderedPage <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> Page {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="com">/**
+ * @see Page#getTemplate()
+ */</span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> String getTemplate() {
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">return</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"/border.htm"</span>;
+ }
+}</pre><p>The BorderedPage template <code class="varname">border.htm</code>:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><html></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><title></span><code class="varname">$title</code><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></title></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><link</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">rel</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"stylesheet"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">type</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"text/css"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">href</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"style.css"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">title</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"Style"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">/></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><body></span>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><h2</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">class</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"title"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">></span><code class="varname">$title</code><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></h2></span>
+
+ <span class="command"><strong>#parse</strong></span>(<code class="varname">$path</code>)
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></body></span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></html></span>
+ </pre><p>Other pages insert their content into this template using the Velocity
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../velocity/vtl-reference-guide.html#parse" target="_blank">#parse</a>
+ directive, passing it their contents pages
+ <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../click-api/org/apache/click/Page.html#path" target="_blank">path</a>. The
+ <code class="varname">$path</code> value is automatically added to the VelocityContext
+ by the ClickServlet.
+ </p><p>An example bordered Home page is provided below:
+ </p><div class="literallayout"><p><page path="<code class="varname">home.htm</code>" classname="<span class="token">Home</span>"/></p></div><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">class</span> Home <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">extends</span> BorderedPage {
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="kwd">public</span> String title = <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="str">"Home"</span>;
+
+}</pre><p>The Home page's content <code class="varname">home.htm</code>:
+ </p><div class="literallayout"><p><b>Welcome</b> to Home page your starting point for the application.</p></div><p>When a request is made for the Home page (home.htm) Velocity will
+ merge the <code class="varname">border.htm</code> page and <code class="varname">home.htm</code>
+ page together returning:
+ </p><pre class="programlisting"><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><html></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><title></span>Home<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></title></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><link</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">rel</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"stylesheet"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">type</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"text/css"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">href</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"style.css"</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">title</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"Style"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">/></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></head></span>
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><body></span>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><h2</span> <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="atn">class</span>=<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="pln">"title"</span><span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag">></span>Home<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></h2></span>
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"><b></span>Welcome<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></b></span> to Home page your application starting point.
+
+ <span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></body></span>
+<span xmlns:fo="http://www.w3.org/1999/XSL/Format" class="tag"></html></span></pre><p>Which may be rendered as:
+ </p><div class="figure"><a name="home-page-screenshot"></a><div class="figure-contents"><div class="mediaobject"><img src="images/pages/home-page-screenshot.png" alt="Home Page"></div></div><p xmlns:fo="http://www.w3.org/1999/XSL/Format" class="title"><i>Figure 2.4. Home Page</i></p></div><br class="figure-break"><p>Note how the Home page class defines a <code class="varname">title</code> model
+ value which is referenced in the <code class="varname">border.htm</code> template as
+ <code class="varname">$title</code>. Each bordered page can define their own title
+ which is rendered in this template.
+ </p><p>Templating with JSP pages is also supported using the same pattern.
+ Please see the Click Examples application for a demonstration.
+ </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch02s07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.5. Page Navigation </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.7. Direct Rendering</td></tr></table></div></body></html>
\ No newline at end of file
Propchange: click/trunk/tools/eclipse/org.apache.click.eclipse/documentation/user-guide/ch02s06.html
------------------------------------------------------------------------------
svn:mime-type = text/plain