Author: buildbot
Date: Sat Aug 8 20:19:48 2015
New Revision: 961182
Log:
Production update by buildbot for tapestry
Modified:
websites/production/tapestry/content/cache/main.pageCache
websites/production/tapestry/content/implementing-the-hi-lo-guessing-game.html
Modified: websites/production/tapestry/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.
Modified:
websites/production/tapestry/content/implementing-the-hi-lo-guessing-game.html
==============================================================================
---
websites/production/tapestry/content/implementing-the-hi-lo-guessing-game.html
(original)
+++
websites/production/tapestry/content/implementing-the-hi-lo-guessing-game.html
Sat Aug 8 20:19:48 2015
@@ -68,7 +68,7 @@
<div id="content">
<div id="ConfluenceContent"><p><span style="line-height: 1.4285715;"><br
clear="none"></span></p><p><span style="line-height: 1.4285715;">Let's start
building a basic Hi-Lo Guessing game.</span></p><p>In the game, the computer
selects a number between 1 and 10. You try and guess the number, clicking
links. At the end, the computer tells you how many guesses you required to
identify the target number. Even a simple example like this will demonstrate
several important concepts in Tapestry:</p><ul><li>Breaking an application into
individual pages</li><li>Transferring information from one page to
another</li><li>Responding to user interactions</li><li>Storing client
information in the server-side session</li></ul><p>We'll build this little
application in small pieces, using the kind of iterative development that
Tapestry makes so easy.</p><p><span
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image"
src="implementing-the-hi-lo-guessing-game.data/hilo-flow.png"
></span></p><p>Our page flow is very simple, consisting of three pages: Index
>(the starting page), Guess and GameOver. The Index page introduces the
>application and includes a link to start guessing. The Guess page presents
>the user with ten links, plus feedback such as "too low" or "too high". The
>GameOver page tells the user how many guesses they took before finding the
>target number.</p><h1 id="ImplementingtheHi-LoGuessingGame-IndexPage">Index
>Page</h1><p>Let's get to work on the Index page and template. Make Index.tml
>look like this:</p><div class="code panel pdl" style="border-width:
>1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width:
>1px;"><b>Index.tml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><html t:type="layout" title="Hi/Lo Guess"
- xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<p>
I'm thinking of a number between one and ten ...
@@ -157,7 +157,7 @@ public class Index
</pre>
</div></div><p>The new event handler method now chooses the target number, and
tells the Guess page about it. Because Tapestry is a managed environment, we
don't just create an instance of Guess ... it is Tapestry's responsibility to
manage the life cycle of the Guess page. Instead, we ask Tapestry for the Guess
page, using the @InjectPage annotation.</p><div
class="confluence-information-macro confluence-information-macro-note"><span
class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>All fields in a Tapestry page or
component class must be <strong>non-public</strong>.</p></div></div><p>Once we
have that Guess page instance, we can invoke methods on it
normally.</p><p>Returning a page instance from an event handler method directs
Tapestry to send a client-side redirect to the returned page, rather than
sending a redirect for the active page. Thus once the user clicks the "start
guessing" lin
k, they'll see the Guess page.</p><div class="confluence-information-macro
confluence-information-macro-warning"><span class="aui-icon aui-icon-small
aui-iconfont-error confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>When creating your own
applications, make sure that the objects stored in final variables are thread
safe. It seems counter-intuitive, but final variables are shared across many
threads. Ordinary instance variables are not. Fortunately, the implementation
of Random is, in fact, thread safe.</p></div></div><p>So ... let's click the
link and see what we get:</p><p><span
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image"
src="implementing-the-hi-lo-guessing-game.data/guess-template-missing.png"></span></p><p>Ah!
We didn't create a Guess page template. Tapestry was really expecting us to
create one, so we better do so.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader pan
elHeader pdl" style="border-bottom-width:
1px;"><b>src/main/resources/com/example/tutorial/pages/Guess.tml</b></div><div
class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"><html t:type="layout" title="Guess The Number"
- xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<p>
The secret number is: ${target}.
@@ -176,7 +176,7 @@ public class Index
</pre>
</div></div><p>This doesn't have anything to do with database persistence
(that's coming up in a later chapter). It means that the value is stored in the
HttpSession between requests.</p><p>Go back to the Index page and click the
link again. Finally, we have a target number:</p><p><span
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image"
src="implementing-the-hi-lo-guessing-game.data/guess-target.png"></span></p><p>That's
enough for us to get started. Let's build out the Guess page, and get ready to
let the user make guesses. We'll show the count of guesses, and increment that
count when they make them. We'll worry about high and low and actually
selecting the correct value later.</p><p>When building Tapestry pages, you
sometimes start with the Java code and build the template to match, and
sometime start with the template and build the Java code to match. Both
approaches are valid. Here, lets start with the markup in the template, then
figure out what we
need in the Java code to make it work.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Guess.tml (revised)</b></div><div
class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><html t:type="layout" title="Guess The Number"
- xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<p>
@@ -281,7 +281,7 @@ public class GameOver
</pre>
</div></div><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>GameOver.tml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"><html t:type="layout" title="Game Over"
- xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<p>