Author: buildbot
Date: Sat Dec 13 15:19:32 2014
New Revision: 932583

Log:
Production update by buildbot for tapestry

Modified:
    websites/production/tapestry/content/cache/main.pageCache
    
websites/production/tapestry/content/using-tapestry-with-hibernate.data/index-grid-v1.png
    websites/production/tapestry/content/using-tapestry-with-hibernate.html

Modified: websites/production/tapestry/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: 
websites/production/tapestry/content/using-tapestry-with-hibernate.data/index-grid-v1.png
==============================================================================
Binary files - no diff available.

Modified: 
websites/production/tapestry/content/using-tapestry-with-hibernate.html
==============================================================================
--- websites/production/tapestry/content/using-tapestry-with-hibernate.html 
(original)
+++ websites/production/tapestry/content/using-tapestry-with-hibernate.html Sat 
Dec 13 15:19:32 2014
@@ -74,7 +74,7 @@ table.ScrollbarTable td.ScrollbarParent
 table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
 table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 
16px;border: none;}
 
-/*]]>*/</style><div class="Scrollbar"><table class="ScrollbarTable"><tr><td 
colspan="1" rowspan="1" class="ScrollbarPrevIcon"><a shape="rect" 
href="using-beaneditform-to-create-user-forms.html"><img align="middle" 
border="0" src="https://cwiki.apache.org/confluence/images/icons/back_16.gif"; 
width="16" height="16"></a></td><td colspan="1" rowspan="1" 
class="ScrollbarPrevName" width="33%"><a shape="rect" 
href="using-beaneditform-to-create-user-forms.html">Using BeanEditForm To 
Create User Forms</a>&#160;</td><td colspan="1" rowspan="1" 
class="ScrollbarParent" width="33%"><sup><a shape="rect" 
href="tapestry-tutorial.html"><img align="middle" border="0" 
src="https://cwiki.apache.org/confluence/images/icons/up_16.gif"; width="8" 
height="8"></a></sup><a shape="rect" href="tapestry-tutorial.html">Tapestry 
Tutorial</a></td><td colspan="1" rowspan="1" class="ScrollbarNextName" 
width="33%">&#160;</td></tr></table></div><p>So, you fill in all the fields, 
submit the form (without validation erro
 rs) and voila: you get back the same form, blanked out. What happened, and 
where did the data go?</p><p>What happened is that we haven't told Tapestry 
what to do after the form is successfully submitted (by successful, we mean, 
with no validation errors). Tapestry's default behavior is to redisplay the 
active page, and that occurs in a new request, with a new instance of the 
Address object (because the address field is not a peristent 
field).</p><p>Well, since we're creating objects, we might as well store them 
somewhere ... in a database. We're going to quickly integrate Tapestry with <a 
shape="rect" class="external-link" href="http://hibernate.org"; >Hibernate</a> 
as the object/relational mapping layer, and ultimately store our data inside a 
<a shape="rect" class="external-link" href="http://www.hsqldb.org/"; >HSQLDB</a> 
database. HSQLDB is an embedded database engine and requires no installation 
&#8211; it will be pulled down as a dependency via maven.</p><h2 
id="UsingTapestryWithH
 ibernate-Re-configuringtheProject">Re-configuring the Project</h2><p>We're 
going to bootstrap this project from a simple Tapestry project to one that uses 
Hibernate and HSQLDB.</p><h3 
id="UsingTapestryWithHibernate-UpdatingtheDependencies">Updating the 
Dependencies</h3><p>First, we must update the POM to list a new set of 
dependencies, that includes Hibernate, the Tapestry/Hibernate integration 
library, and the HSQLDB JDBC driver:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="border-bottom-width: 1px;"><b>src/pom.xml (partial)</b></div><div 
class="codeContent panelContent pdl">
+/*]]>*/</style><div class="Scrollbar"><table class="ScrollbarTable"><tr><td 
colspan="1" rowspan="1" class="ScrollbarPrevIcon"><a shape="rect" 
href="using-beaneditform-to-create-user-forms.html"><img align="middle" 
border="0" src="https://cwiki.apache.org/confluence/images/icons/back_16.gif"; 
width="16" height="16"></a></td><td colspan="1" rowspan="1" 
class="ScrollbarPrevName" width="33%"><a shape="rect" 
href="using-beaneditform-to-create-user-forms.html">Using BeanEditForm To 
Create User Forms</a>&#160;</td><td colspan="1" rowspan="1" 
class="ScrollbarParent" width="33%"><sup><a shape="rect" 
href="tapestry-tutorial.html"><img align="middle" border="0" 
src="https://cwiki.apache.org/confluence/images/icons/up_16.gif"; width="8" 
height="8"></a></sup><a shape="rect" href="tapestry-tutorial.html">Tapestry 
Tutorial</a></td><td colspan="1" rowspan="1" class="ScrollbarNextName" 
width="33%">&#160;</td></tr></table></div><p>So, you fill in all the fields, 
submit the form (without validation erro
 rs) and voila: you get back the same form, blanked out. What happened, and 
where did the data go?</p><p>What happened is that we haven't told Tapestry 
what to do after the form is successfully submitted (by successful, we mean, 
with no validation errors). Tapestry's default behavior is to redisplay the 
active page, and that occurs in a new request, with a new instance of the 
Address object (because the address field is not a peristent 
field).</p><p>Well, since we're creating objects, we might as well store them 
somewhere ... in a database. We're going to quickly integrate Tapestry with <a 
shape="rect" class="external-link" href="http://hibernate.org"; >Hibernate</a> 
as the object/relational mapping layer, and ultimately store our data inside a 
<a shape="rect" class="external-link" href="http://www.hsqldb.org/"; 
>HyperSQL</a> (HSQLDB) database. HSQLDB is an embedded database engine and 
requires no installation &#8211; it will be pulled down as a dependency by 
Maven.</p><h2 id="UsingTap
 estryWithHibernate-Re-configuringtheProject">Re-configuring the 
Project</h2><p>We're going to bootstrap this project from a simple Tapestry 
project to one that uses Hibernate and HSQLDB.</p><h3 
id="UsingTapestryWithHibernate-UpdatingtheDependencies">Updating the 
Dependencies</h3><p>First, we must update the POM to list a new set of 
dependencies, that includes Hibernate, the Tapestry/Hibernate integration 
library, and the HSQLDB JDBC driver:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="border-bottom-width: 1px;"><b>src/pom.xml (partial)</b></div><div 
class="codeContent panelContent pdl">
 <script class="theme: Default; brush: xml; gutter: false" 
type="syntaxhighlighter"><![CDATA[    &lt;dependencies&gt;
 
         &lt;dependency&gt;
@@ -186,11 +186,11 @@ public class CreateAddress
     }
 }
 ]]></script>
-</div></div><p>The <a shape="rect" class="external-link" 
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html";>Inject</a>
 annotation tells Tapestry to inject a service into the annotated field; 
Tapestry includes a sophisticated Inversion of Control container (similar in 
many ways to Spring) that is very good at locating available services by type, 
rather than by a string id. In any case, the Hibernate Session object is 
exposed as a Tapestry IoC service, ready to be injected (this is one of the 
things provided by the tapestry-hibernate module).</p><p>Tapestry automatically 
starts a transaction as necessary; however that transaction will be 
<em>aborted</em> at the end of the request by default. If we make changes to 
persistent objects, such as adding a new Address object, then it is necessary 
to commit the transaction.</p><p>The <a shape="rect" class="external-link" 
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/hiber
 nate/annotations/CommitAfter.html">CommitAfter</a> annotation can be applied 
to any component method; if the method completes normally, the transaction will 
be committed (and a new transaction started to replace the committed 
transaction).</p><p>After persisting the new address, we return to the main 
Index page of the application.</p><p><em>Note: In real applications, it is rare 
to have pages and components directly use the Hibernate Session. It is 
generally a better approach to define your own Data Access Object layer to 
perform common update operations and queries.</em></p><h2 
id="UsingTapestryWithHibernate-ShowingAddresses">Showing Addresses</h2><p>As a 
little preview of what's next, let's display all the Addresses entered by the 
user on the Index page of the application. After you enter a few names, it will 
look something like:</p><p><img class="confluence-embedded-image 
confluence-content-image-border" 
src="https://cwiki.apache.org/confluence/download/attachments/23340507/index
 -grid-v1.png?version=3&amp;modificationDate=1418479523098&amp;api=v2" 
data-image-src="/confluence/download/attachments/23340507/index-grid-v1.png?version=3&amp;modificationDate=1418479523098&amp;api=v2"></p><h2
 id="UsingTapestryWithHibernate-AddingtheGridtotheIndexpage">Adding the Grid to 
the Index page</h2><p>So, how is this implemented? Primarily, its accomplished 
by the <a shape="rect" class="external-link" 
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Grid.html";>Grid</a>
 component.</p><p>The Grid component is based on the same concepts as the 
BeanEditForm component; it can pull apart a bean into columns. The columns are 
sortable, and when there are more entries than will fit on a single page, page 
navigation is automatically added.</p><p>A minimal Grid is very easy to add to 
the template. Just add this near the bottom of Index.tml:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="b
 order-bottom-width: 1px;"><b>src/main/webapp/Index.tml (partial)</b></div><div 
class="codeContent panelContent pdl">
+</div></div><p>The <a shape="rect" class="external-link" 
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html";>Inject</a>
 annotation tells Tapestry to inject a service into the annotated field; 
Tapestry includes a sophisticated Inversion of Control container (similar in 
many ways to Spring) that is very good at locating available services by type, 
rather than by a string id. In any case, the Hibernate Session object is 
exposed as a Tapestry IoC service, ready to be injected (this is one of the 
things provided by the tapestry-hibernate module).</p><p>Tapestry automatically 
starts a transaction as necessary; however that transaction will be 
<em>aborted</em> at the end of the request by default. If we make changes to 
persistent objects, such as adding a new Address object, then it is necessary 
to commit the transaction.</p><p>The <a shape="rect" class="external-link" 
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/hiber
 nate/annotations/CommitAfter.html">CommitAfter</a> annotation can be applied 
to any component method; if the method completes normally, the transaction will 
be committed (and a new transaction started to replace the committed 
transaction).</p><p>After persisting the new address, we return to the main 
Index page of the application.</p><p><em>Note: In real applications, it is rare 
to have pages and components directly use the Hibernate Session. It is 
generally a better approach to define your own Data Access Object layer to 
perform common update operations and queries.</em></p><h2 
id="UsingTapestryWithHibernate-ShowingAddresses">Showing Addresses</h2><p>As a 
little preview of what's next, let's display all the Addresses entered by the 
user on the Index page of the application. After you enter a few names, it will 
look something like:</p><p><img class="confluence-embedded-image 
confluence-content-image-border" 
src="https://cwiki.apache.org/confluence/download/attachments/23340507/index
 -grid-v1.png?version=4&amp;modificationDate=1418482289909&amp;api=v2" 
data-image-src="/confluence/download/attachments/23340507/index-grid-v1.png?version=4&amp;modificationDate=1418482289909&amp;api=v2"></p><h2
 id="UsingTapestryWithHibernate-AddingtheGridtotheIndexpage">Adding the Grid to 
the Index page</h2><p>So, how is this implemented? Primarily, its accomplished 
by the <a shape="rect" class="external-link" 
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Grid.html";>Grid</a>
 component.</p><p>The Grid component is based on the same concepts as the 
BeanEditForm component; it can pull apart a bean into columns. The columns are 
sortable, and when there are more entries than will fit on a single page, page 
navigation is automatically added.</p><p>A minimal Grid is very easy to add to 
the template. Just add this near the bottom of Index.tml:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" 
style="b
 order-bottom-width: 1px;"><b>src/main/webapp/Index.tml (partial)</b></div><div 
class="codeContent panelContent pdl">
 <script class="theme: Default; brush: xml; gutter: false" 
type="syntaxhighlighter"><![CDATA[  &lt;t:grid source=&quot;addresses&quot;
-         
reorder=&quot;honorific,firstName,lastName,street1,street2,city,state,zip,email,phone&quot;/&gt;
+         
include=&quot;honorific,firstName,lastName,street1,city,state,zip,phone&quot;/&gt;
 ]]></script>
-</div></div><p>Note that the Grid component accepts the same "reorder" 
parameter that we used with the BeanEditForm.</p><p>Now all we have to do is 
supply the addresses property in the Java code. Here's how Index.java should 
look now:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeHeader panelHeader pdl" style="border-bottom-width: 
1px;"><b>src/main/java/com/example/tutorial/pages/Index.java</b></div><div 
class="codeContent panelContent pdl">
+</div></div><p>Note that the Grid component accepts many of the same 
parameters that we used with the BeanEditForm. Here we use the include 
parameter to specify the properties to show, and in what order.</p><p>Now all 
we have to do is supply the addresses property in the Java code. Here's how 
Index.java should look now:</p><div class="code panel pdl" style="border-width: 
1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 
1px;"><b>src/main/java/com/example/tutorial/pages/Index.java</b></div><div 
class="codeContent panelContent pdl">
 <script class="theme: Default; brush: java; gutter: false" 
type="syntaxhighlighter"><![CDATA[package com.example.tutorial.pages;
 import java.util.List;
 import org.apache.tapestry5.ioc.annotations.Inject;


Reply via email to