You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by bu...@apache.org on 2013/08/17 23:20:32 UTC
svn commit: r875057 - in /websites/production/tapestry/content:
cache/main.pageCache switching-cases.html
Author: buildbot
Date: Sat Aug 17 21:20:31 2013
New Revision: 875057
Log:
Production update by buildbot for tapestry
Modified:
websites/production/tapestry/content/cache/main.pageCache
websites/production/tapestry/content/switching-cases.html
Modified: websites/production/tapestry/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/tapestry/content/switching-cases.html
==============================================================================
--- websites/production/tapestry/content/switching-cases.html (original)
+++ websites/production/tapestry/content/switching-cases.html Sat Aug 17 21:20:31 2013
@@ -34,9 +34,9 @@
</div>
<div id="top">
-<div id="smallbanner"><div class="searchbox" style="float:right;margin: .3em 1em .1em 1em">
+<div id="smallbanner"><div class="searchbox" style="float:right;margin: .3em 1em .1em 1em"><p>
<span style="color: #999; font-size: 90%">Tapestry docs, issues, wikis & blogs:</span>
-<form enctype="application/x-www-form-urlencoded" method="get" action="http://tapestry.apache.org/search.html">
+</p><form enctype="application/x-www-form-urlencoded" method="get" action="http://tapestry.apache.org/search.html">
<input type="text" name="q">
<input type="submit" value="Search">
</form>
@@ -71,77 +71,79 @@ table.ScrollbarTable td.ScrollbarNextIco
<p>With Tapestry's <tt>If</tt> component you can only test one condition at a time. In order to distinguish multiple cases, you'd have to write complex nested if/else constructs in your page template and have a checker method for each test inside your page class.</p>
+<div class="navmenu" style="float:right; background:#eee; margin:3px; padding:0 1em"><p> <b>JumpStart Demo:</b><br clear="none">
+ <a shape="rect" class="external-link" href="http://jumpstart.doublenegative.com.au/jumpstart/examples/lang/ifnotnegateswitchelseunless" >If, Not, Negate, Switch, Else, Unless</a></p></div>
+
<p>In cases where you have to distinguish multiple cases, the <tt>Delegate</tt> component comes in. It delegates rendering to some other component, for example a <tt>Block</tt>. For each case you have, you basically wrap the content inside a <tt>Block</tt> that doesn't get rendered by default. You then place a Delegate component on your page and point it to a method inside your page class that will decide which of your Blocks should be rendered.</p>
<p>Imagine for example a use case, where you want to distinguish between 4 cases and you have an int property called <tt>whichCase</tt> that should be tested against. Your page template would look as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>SwitchMe.tml</b></div><div class="codeContent panelContent">
-<pre class="code-xml">
-<span class="code-tag"><html <span class="code-keyword">xmlns:t</span>=<span class="code-quote">"http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"</span>></span>
- <span class="code-tag"><body></span>
- <span class="code-tag"><h1></span>Switch<span class="code-tag"></h1></span>
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+ <body>
+ <h1>Switch</h1>
- <span class="code-tag"><t:delegate to=<span class="code-quote">"case"</span>/></span>
+ <t:delegate to="case"/>
- <span class="code-tag"><t:block t:id=<span class="code-quote">"case1"</span>></span>
+ <t:block t:id="case1">
Here is the content for case1.
- <span class="code-tag"></t:block></span>
+ </t:block>
- <span class="code-tag"><t:block t:id=<span class="code-quote">"case2"</span>></span>
+ <t:block t:id="case2">
Here is the content for case2.
- <span class="code-tag"></t:block></span>
+ </t:block>
- <span class="code-tag"><t:block t:id=<span class="code-quote">"case3"</span>></span>
+ <t:block t:id="case3">
Here is the content for case3.
- <span class="code-tag"></t:block></span>
+ </t:block>
- <span class="code-tag"><t:block t:id=<span class="code-quote">"case4"</span>></span>
+ <t:block t:id="case4">
Here is the content for case4.
- <span class="code-tag"></t:block></span>
- <span class="code-tag"></body></span>
-<span class="code-tag"></html></span>
-</pre>
+ </t:block>
+ </body>
+</html>
+]]></script>
</div></div>
<p>You can see, that the <tt>Delegate</tt> component's <tt>to</tt> parameter is bound to the case property of your page class. In your page class you therefore have a <tt>getCase()</tt> method that is responsible for telling the <tt>Delegate</tt> component which component should be rendered. For that we are injecting references to the <tt>Block}}s defined in your page template into the page class and return the according {{Block</tt> in the <tt>getCase()</tt> method.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>SwitchMe.java</b></div><div class="codeContent panelContent">
-<pre class="code-java">
-<span class="code-keyword">public</span> class SwitchMe
+<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[
+public class SwitchMe
{
@Persist
- <span class="code-keyword">private</span> <span class="code-object">int</span> whichCase;
+ private int whichCase;
@Inject
- <span class="code-keyword">private</span> Block case1, case2, case3, case4;
+ private Block case1, case2, case3, case4;
- <span class="code-keyword">public</span> <span class="code-object">Object</span> getCase()
+ public Object getCase()
{
- <span class="code-keyword">switch</span> (whichCase)
+ switch (whichCase)
{
- <span class="code-keyword">case</span> 1:
- <span class="code-keyword">return</span> case1;
- <span class="code-keyword">case</span> 2:
- <span class="code-keyword">return</span> case2;
- <span class="code-keyword">case</span> 3:
- <span class="code-keyword">return</span> case3;
- <span class="code-keyword">case</span> 4:
- <span class="code-keyword">return</span> case4;
- <span class="code-keyword">default</span>:
- <span class="code-keyword">return</span> <span class="code-keyword">null</span>;
+ case 1:
+ return case1;
+ case 2:
+ return case2;
+ case 3:
+ return case3;
+ case 4:
+ return case4;
+ default:
+ return null;
}
}
}
-</pre>
+]]></script>
</div></div>
-<p>Happy switching!</p>
-</div>
+<p>Happy switching!</p></div>
</div>
<div class="clearer"></div>
<div id="footer">
-<div id="footer"><p>Apache Tapestry, Tapestry, Apache, the Apache feather logo, and the Apache Tapestry project logo are trademarks of The Apache Software Foundation.</p>
+<div id="footer"><p>Apache Tapestry, Tapestry, Apache, the Apache feather logo, and the Apache Tapestry project logo are trademarks of The Apache Software Foundation.<br clear="none">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-400821-1']);
@@ -152,7 +154,7 @@ table.ScrollbarTable td.ScrollbarNextIco
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
-</script></div>
+</script></p></div>
</div>
<div id="comments_thread"></div>
<script type="text/javascript" src="https://comments.apache.org/show_comments.lua?site=tapestry&page=http://tapestry.apache.org/switching-cases.html" async="true">