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
Feb 3 22:21:02 2018
@@ -188,7 +188,7 @@ public class CreateAddress
}
}
</pre>
-</div></div><p>The <a 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 class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/hibernate/annotations/CommitA
fter.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><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image confluence-external-resource
confluence-content-image-border" src="https://cwiki-test.
apache.org/confluence/download/attachments/23340507/index-grid-v1.png?version=4&modificationDate=1418482289000&api=v2"
data-image-src="https://cwiki-test.apache.org/confluence/download/attachments/23340507/index-grid-v1.png?version=4&modificationDate=1418482289000&api=v2"></span></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 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="border-bottom-width: 1px;"><b>src/main/webapp/Index.tml
(partial)</b></div><div class="codeContent panelContent pdl">
+</div></div><p>The <a 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 class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/hibernate/annotations/CommitA
fter.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><span class="confluence-embedded-file-wrapper
confluence-embedded-manual-size"><img class="confluence-embedded-image"
width="722" src="using-tapestry-with-hibernate.data/i
ndex-grid-v1.png"></span></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 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="border-bottom-width: 1px;"><b>src/main/webapp/Index.tml
(partial)</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default"
style="font-size:12px;"> <t:grid source="addresses"
include="honorific,firstName,lastName,street1,city,state,zip,phone"/>
</pre>
@@ -208,7 +208,7 @@ public class Index
}
}
</pre>
-</div></div><p>Here, we're using the Hibernate Session object to find all
Address objects in the database. Any sorting that takes place will be done in
memory. This is fine for now (with only a handful of Address objects in the
database). Later we'll see how to optimize this for very large result
sets.</p><h2 id="UsingTapestryWithHibernate-What'sNext?">What's Next?</h2><p>We
have lots more to talk about: more components, more customizations, built-in
Ajax support, more common design and implementation patterns, and even writing
your own components (which is easy!).</p><p>Check out the many Tapestry
resources available on the <a href="using-tapestry-with-hibernate.html">Using
Tapestry With Hibernate</a> page, including the <a
href="using-tapestry-with-hibernate.html">Using Tapestry With Hibernate</a> and
<a href="using-tapestry-with-hibernate.html">FAQ</a> pages and the <a
href="using-tapestry-with-hibernate.html">Using Tapestry With Hibernate</a>. Be
sure to peruse the <a href=
"using-tapestry-with-hibernate.html">Using Tapestry With Hibernate</a>, which
provides comprehensive details on nearly every Tapestry topic. Finally, be sure
to visit (and bookmark) <a class="external-link"
href="http://jumpstart.doublenegative.com.au/jumpstart7/"
rel="nofollow">Tapestry JumpStart</a>, which provides a nearly exhaustive set
of tutorials.</p><p> </p><p></p></div>
+</div></div><p>Here, we're using the Hibernate Session object to find all
Address objects in the database. Any sorting that takes place will be done in
memory. This is fine for now (with only a handful of Address objects in the
database). Later we'll see how to optimize this for very large result
sets.</p><h2 id="UsingTapestryWithHibernate-What'sNext?">What's Next?</h2><p>We
have lots more to talk about: more components, more customizations, built-in
Ajax support, more common design and implementation patterns, and even writing
your own components (which is easy!).</p><p class="confluence-link">Check out
the many Tapestry resources available on the <a
href="documentation.html">Documentation</a> page, including the <a
href="getting-started.html">Getting Started</a> and <a
href="frequently-asked-questions.html">FAQ</a> pages and the <a
href="cookbook.html">Cookbook</a>. Be sure to peruse the <a
href="user-guide.html">User Guide</a>, which provides comprehensive details
on nearly every Tapestry topic. Finally, be sure to visit (and bookmark) <a
class="external-link" href="http://jumpstart.doublenegative.com.au/jumpstart"
rel="nofollow">Tapestry JumpStart</a>, which provides a nearly exhaustive set
of tutorials.</p><p> </p><p></p></div>
</div>
<div class="clearer"></div>