<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Carol McDonald&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/" />
<modified>2008-04-29T03:35:33Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2008, caroljmcdonald</copyright>
<entry>
<title>Sample Store Catalog using using Groovy and Grails</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/04/sample_store_ca.html" />
<modified>2008-04-29T03:35:33Z</modified>
<issued>2008-04-29T03:35:16Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.9626</id>
<created>2008-04-29T03:35:16Z</created>
<summary type="text/plain">This Catalog Sample app demonstrates the usage of Groovy and Grails to implement pagination of data sets for a Store Catalog.</summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Web Applications</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>grailsexample</title>
</head>
<body>
<h2>Sample Store Catalog using using Groovy and Grails</h2>
<br>
<br>
This Catalog Sample app demonstrates the usage of Groovy and Grails to
implement pagination of data sets for a Store Catalog.<br>
<a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=9118&amp;expandFolder=9118&amp;folderID=9118">
download Catalog sample code </a><br>
<br>
<b>Overview of the Technologies and Frameworks in the Sample Application<br>
<br>
</b><a href="http://grails.codehaus.org/">Grails</a> aims to bring the
"coding by convention" paradigm to Groovy. It's an open-source web
application framework that leverages the Groovy language and
complements Java Web development. <br>
<p> <a href="http://groovy.codehaus.org/">Groovy</a> is an agile and <b>dynamic
language</b> for the <b>Java Virtual Machine,</b> it<b> </b>compiles
to Java bytecode<b>, </b>and it combines popular features from
languages such as Smalltalk, Python, and Ruby. </p>
Grails is a
Model-View-Controller based framework that simplifies the development
of&nbsp; web applications by reducing the need for configuration files
and by generating a lot of the things needed in
a database-backed Web application.<br>
<br>
<h4>

<img alt="mvc.gif" src="http://weblogs.java.net/blog/caroljmcdonald/archive/mvc.gif" 
style="width: 304px; height: 334px;" />

<br>
</h4>
<br>
<p><b><br>
The Sample Application</b>
</p>
The sample application displays an online catalog of pets sold in a pet
store. The image below shows the Catalog Listing page, which allows a
user to
page through a list of items
in a store.
<br>
<br>
<div style="margin-left: 40px;">&nbsp;

 
<img alt="listpet.jpg" src="http://weblogs.java.net/blog/caroljmcdonald/archive/listpet.jpg" 
width="353" height="532" />

 <br>
</div>
<br>
<br>
<h4>The Model - Grails Domain Classes<br>
</h4>
The Model is your application's persistent business domain objects.
A Grails domain
object
instance represents a row in a database table.&nbsp; The command <code>grails
create-domain-class Item</code> generates the <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item.groovy</span></code>
class shown below corresponding to the item table. <br>
<br>
After model code
generation you have to
add the domain object's attributes and relationships. The <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item</span></code>
class has a many-to-one relationship
with the <code><span style="color: rgb(0, 0, 153); font-weight: bold;">Address</span></code>
class. In Grails <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">hasMany</span></code>
is the
many end of a many-to-one&nbsp; relationship. <br>
<br>
<br>
<table>
  <tbody>
    <tr>
      <td>
      <table class="examplecode" border="1" cellpadding="2"
 cellspacing="0">
        <tbody>
          <tr class="bg-white">
            <td><b>Code Sample from: </b><span
 style="font-weight: bold;">domain\</span><b>Item.groovy <br>
            </b></td>
          </tr>
          <tr>
            <td> <code><br>
class <span style="color: rgb(0, 0, 153); font-weight: bold;">Item</span>
{<br>
&nbsp; Long id<br>
&nbsp; String name<br>
&nbsp; String description<br>
&nbsp; String imageurl<br>
&nbsp; String imagethumburl<br>
&nbsp; BigDecimal price<br>
&nbsp; <span style="color: rgb(0, 0, 153); font-weight: bold;">Address</span>
            <span style="color: rgb(0, 0, 153); font-weight: bold;">address</span><br>
}<br>
&nbsp;&nbsp;&nbsp; </code><code><br>
            <br>
            </code> </td>
          </tr>
        </tbody>
      </table>
      </td>
      <td>&nbsp; <br>
      </td>
      <td>
      <table class="examplecode" border="1" cellpadding="2"
 cellspacing="0">
        <tbody>
          <tr class="bg-white">
            <td><b>Code Sample from: </b><span
 style="font-weight: bold;">domain\</span><b>Address.groovy <br>
            </b></td>
          </tr>
          <tr>
            <td> <code><br>
class <span style="color: rgb(0, 0, 153); font-weight: bold;">Address</span>
{<br>
&nbsp; Long id <br>
&nbsp; String street1 <br>
&nbsp; String street2 <br>
&nbsp; String city <br>
&nbsp; String state <br>
&nbsp; String zip <br>
&nbsp; float latitude <br>
&nbsp; float longitude <br>
&nbsp; <span style="color: rgb(0, 0, 153); font-weight: bold;">static
hasMany = [item:Item]</span><br>
}<br>
&nbsp;&nbsp;&nbsp; </code><code><br>
            <br>
            </code> </td>
          </tr>
        </tbody>
      </table>
      </td>
    </tr>
  </tbody>
</table>
<br>
<img alt="classrel.gif"
 src="http://weblogs.java.net/blog/caroljmcdonald/archive/classrel.gif"
 height="134" width="274">
<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>SQL&nbsp; Sample for items table<span
 style="font-family: monospace;"><br>
      </span></b></td>
    </tr>
    <tr>
      <td> <code><br>
CREATE TABLE item (<br>
&nbsp;id BIGINT NOT NULL,<br>
&nbsp;product_id BIGINT NOT NULL,<br>
&nbsp;name VARCHAR(30) NOT NULL,<br>
&nbsp;description VARCHAR(500) NOT NULL,<br>
&nbsp;imageurl VARCHAR(55),<br>
&nbsp;imagethumburl VARCHAR(55),<br>
&nbsp;price DECIMAL(14,2) NOT NULL,<br>
&nbsp;address_id BIGINT NOT NULL,<br>
&nbsp;primary key (id),<br>
&nbsp;foreign key (address_id) references address(id),<br>
&nbsp;foreign key (product_id) references product(id)<br>
);<br>
&nbsp;&nbsp;&nbsp; </code><code><br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
Groovy with Grails dynamically generates getters and setters and the
dynamic
methods Item.save(), Item.delete(),&nbsp; Item.list(), Item.get() to
retrieve/update data from/to
the db table. <br>
<br>
Grails Object Relational Mapping (GORM) is currently built on top of
Hibernate but you don't have to know Hibernate to use it
( <a href="http://grails.codehaus.org/Roadmap">Grails&nbsp; 1.1 will
support&nbsp; the Java Persistence API</a>) .<br>
<br>
<br>
<code></code><span style="font-weight: bold;">The Controller</span><br>
<br>
Controllers handle incoming http requests, interact with the model to
get data and to process requests,&nbsp; invoke the correct view, and
direct domain data to the view for display.&nbsp;
In Grails, http requests are handled by Controller classes which
are made up
of one or more action methods that are executed on request and then
either&nbsp;render
a Groovy Server Page or redirect to another
action. Grails routes requests to the controller action which
corresponds to the URL mapping for the request. In Grails the default
mapping from URL to action method follows this convention: http://host/<span
 style="font-weight: bold;">app/controller/action/id</span> .&nbsp; For
example the URL <span style="font-weight: bold;">http://host/catalog/item/list</span>
calls the
<span style="font-weight: bold;">list </span><span
 style="font-family: monospace; font-weight: bold;"><span
 style="color: rgb(0, 0, 153);"></span></span><span
 style="font-weight: bold;">action</span> method in the<span
 style="font-weight: bold;"> item controller</span> <span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></span>class
shown below.&nbsp;&nbsp; &nbsp; <a
 href="http://grails.codehaus.org/Scaffolding">Grails
Scaffolding</a> provides a series of standardized
Controller action methods for listing, showing, creating, updating, and
deleting
objects of a class.&nbsp; These standardized actions
come with both controller logic and default view Groovy Server Pages.
The command&nbsp;<code>generate-all</code><code> Item</code>
generates the Item controller and the List, Show, Create, Edit
Groovy Server Pages for the Item domain object. The <span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">ItemController</span></span>
<span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">list</span></span>
action renders a view with a paginated list of item objects.<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from:&nbsp;</b><span style="font-weight: bold;">grails-app\</span><span
 style="font-weight: bold;">controllers\</span><b>ItemController.groovy</b></td>
    </tr>
    <tr>
      <td><span style="font-family: monospace;"><br>
class <span style="color: rgb(0, 0, 153); font-weight: bold;">ItemController</span>
{<br>
      <br>
&nbsp; </span><span style="font-family: monospace;">def index = {
redirect(action:list,params:params) }</span><span
 style="font-family: monospace;"><br>
      <br>
&nbsp; def list = {<br>
&nbsp;&nbsp;&nbsp; if(!params.max) params.max = 10<br>
&nbsp;&nbsp;&nbsp; [ itemList: Item.list( params ) ]<br>
&nbsp; }<br>
. . .<br>
      </span><code> <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
When a URL has a controller but no action (e.g.
http://localhost:8080/catalog/item/&nbsp; ), Grails defaults to the
index action. In the<span style="font-family: mon;"><span
 style="font-weight: bold;"> </span></span><span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">ItemController</span></span>
code the&nbsp;<span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></span> <span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">index</span></span>
action method redirects to the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">list</span></span>
action.&nbsp; The <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">ItemController</span></span>
<span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">list </span></span>action
method calls the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item.list() </span></span>method
which returns an ArrayList of item objects retrieved from the item
database table . If there are more than <span
 style="font-family: monospace;">params.max</span> objects in the
table, Grails creates next and previous pagination links automatically.
The <span style="font-family: monospace;">itemList</span><span
 style="font-family: monospace;"> </span>variable&nbsp; is
automatically made available to the view by the framework.<br>
<br>
After executing
code, actions usually render a GSP in the views directory
corresponding to the name of the controller and action, for example the
list action will render the grails-app\views\item\list.gsp . <br>
<br>
<h4>The View<br>
</h4>
The view layer generates a web
page, using data from domain objects provided by the controller. In
Grails, the view is rendered using <a
 href="http://docs.codehaus.org/display/GRAILS/Developer+-+Groovy+Server+Pages">Groovy
Server Pages</a>. Below is part of the list.gsp for the Catalog
application (note I modified the html table format from the default
generated).<br>
<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><span style="font-weight: bold;">grails-app\</span><span
 style="font-weight: bold;">views\item\</span><b>list.gsp<br>
      </b></td>
    </tr>
    <tr>
      <td> <code><br>
&lt;table&gt;<br>
&nbsp;&nbsp; &lt;thead&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:sortableColumn</span>
property="name" title="Name" /&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;g:sortableColumn
property="imagethumburl" title="Photo" /&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;g:sortableColumn
property="price" title="Price" /&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br>
&nbsp;&nbsp; &lt;/thead&gt;<br>
&nbsp;&nbsp; &lt;tbody&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:each</span>
in="${<span style="color: rgb(0, 0, 153); font-weight: bold;">itemList</span>}"
status="i"
var="<span style="color: rgb(0, 0, 153); font-weight: bold;">item</span>"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr class="${(i % 2) == 0
? 'odd' : 'even'}"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <span style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:link</span>
action="show" id="${item.id}"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
${<span style="color: rgb(0, 0, 153); font-weight: bold;">item.name?.encodeAsHTML()</span>}&lt;/g:link&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;img src="${<span style="color: rgb(0, 0, 153); font-weight: bold;">createLinkTo</span>(dir:'images',file:<span
 style="color: rgb(0, 0, 153); font-weight: bold;">item.imagethumburl</span>)}"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;td&gt;${<span style="color: rgb(0, 0, 153); font-weight: bold;">item.price?.encodeAsHTML()</span>}&lt;/td&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/g:each&gt;<br>
&nbsp; &lt;/tbody&gt;<br>
&nbsp;&lt;/table&gt;<br>
      <br>
&lt;div class="paginateButtons"&gt;<br>
&nbsp;<span style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:paginate</span>
total="${Item.count()}" /&gt;<br>
&lt;/div&gt;<br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
The view uses instance variables<em> </em>set by the controller to
access the data it needs to render the GSP.<br>
<br>
GSP has a GroovyTagLib similar to the&nbsp; JSP tag library. <code
 style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g: </code>are
GroovyTags. <code style="color: rgb(0, 0, 153); font-weight: bold;"><br>
&nbsp;&nbsp; </code><br>
<code><span style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:sortableColumn</span></code><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The <a
 href="http://grails.codehaus.org/GSP+Tag+-+sortableColumn">sortableColumn</a>
tag renders a sortable column to support sorting in tables.<br>
<br style="color: rgb(0, 0, 153); font-weight: bold;">
<code style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:each
in="${itemList}" status="i"
var="item"&gt;</code><br>
<div style="margin-left: 40px;">loops through each object in the&nbsp;<code
 style="color: rgb(0, 0, 153); font-weight: bold;">itemList</code><span
 style="font-family: monospace;"><span style="font-weight: bold;"> </span></span>variable,
which is an ordered <span style="font-family: monospace;"><span
 style="font-weight: bold;"></span></span>ArrayList of <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item </span></code>model
objects,&nbsp; and assigns each <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item</span></code>
model object to the <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item </span></code>variable.<br>
&nbsp;<br>
</div>
<code style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:link
action="show"
id="${item.id}"&gt;${item.name?.encodeAsHTML()}&lt;/g:link&gt;</code><code
 style="color: rgb(0, 0, 153); font-weight: bold;">&nbsp;
</code>
<div style="margin-left: 40px;"><code><a
 href="http://grails.org/doc/1.0.x/ref/Tags/link.html">the
&lt;g:link&gt;</a> </code>GroovyTag creates an html anchor tag <code>href</code>
based on the <code>action</code>, <code>id</code>, <code>controller</code>
parameters specified. In this example it generates a link to the
item/show/id action which when clicked will display the
corresponding item details. For
example this line will generate the following HTML for the variable <code
 style="color: rgb(0, 0, 153); font-weight: bold;">item</code>:
<pre id="line34">&lt;<span class="start-tag">a</span><span
 class="attribute-name"> href</span>=<span class="attribute-value">"/catalog/item/show/2"</span>&gt;Friendly Cat&lt;/<span
 class="end-tag">a</span>&gt;</pre>
</div>
<code><span style="color: rgb(0, 0, 153);"> </span></code>
<code style="color: rgb(0, 0, 153); font-weight: bold;">&lt;img
src="${createLinkTo(dir:'images',file:item.imagethumburl)}"/&gt;</code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">&nbsp;</span>
<div style="margin-left: 40px;">The <a
 href="http://docs.codehaus.org/display/GRAILS/Tag+-+createLinkTo">createLinkTo</a>
tag generates an HTML link for the
<code><span style="color: rgb(0, 0, 153); font-weight: bold;">item's
imagethumburl</span></code> <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></code>attribute.&nbsp;</div>
<br>
<code style="color: rgb(0, 0, 153); font-weight: bold;">${item.price?.encodeAsHTML()}</code><br>
<div style="margin-left: 40px;">displays the value of the&nbsp; <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item 's price </span></code>attribute
as
escaped HTML text.<br>
<br style="color: rgb(0, 0, 153); font-weight: bold;">
</div>
<code style="color: rgb(0, 0, 153); font-weight: bold;">&lt;g:paginate
total="${Item.count()}" /&gt;</code>
<div style="margin-left: 40px;">The <a
 href="http://grails.codehaus.org/GSP+Tag+-+paginate">paginate</a> tag
creates next/previous buttons and a breadcrumb trail to allow
pagination of results using the <code
 style="color: rgb(0, 0, 153); font-weight: bold;">Item.count()</code>
domain method.<br>
</div>
<br>
<h4>The Show Action Method<br>
</h4>
In Grails the mapping for the URL http://host<span
 class="attribute-value">/item/show/1</span>&nbsp; (
http://host/controller/action/<span style="font-weight: bold;">id</span>
)&nbsp; will
route to the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">show</span></span>
action in the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">ItemController</span></span>
passing 1 to the method as the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">id</span></span> of
the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">params </span></span>parameter
hash. The <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">show</span></span>
action of the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">ItemController </span></span>class
is shown below. The <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">ItemController</span></span>
<span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">show</span></span>
action renders a view showing the details of the item object
corresponding to the id parameter.<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><span style="font-weight: bold;">grails-app\controllers\</span><b>ItemController.groovy</b></td>
    </tr>
    <tr>
      <td><span style="font-family: monospace;"><br>
&nbsp;def show = {<br>
&nbsp;&nbsp; def item = <span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item.get</span>( <span
 style="color: rgb(0, 0, 153); font-weight: bold;">params.id</span> )<br>
      <br>
&nbsp;&nbsp; if(!item) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flash.message = "Item not found with id
${params.id}"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; redirect(action:list)<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else { return [ item : item ] }<br>
&nbsp;}<br>
      <br>
      </span><code> <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
The <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">show</span></span>
action method&nbsp; calls the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">Item.get()</span></span>
<span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></span><code></code><span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></span>method
which queries the items table returning the<span
 style="font-family: monospace;"> </span><span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item </span></span>instance
variable corresponding to the item with the attribute <span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">id</span></span>
(primary key)
equal to the&nbsp; <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">id</span></span>
parameter. This is the equivalent of the following sql : <span
 style="font-family: monospace;"></span>select * from items where id='<span
 style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></span>1' .
The <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item</span> </span>variable
is automatically made available to the Show view by the framework.<span
 style="font-weight: bold;"><br>
<br>
</span>
<h4>The Show View GSP<br>
</h4>
After executing
code in the action, the <span style="font-family: monospace;"><span
 style="color: rgb(0, 0, 153); font-weight: bold;">show </span></span>action
renders the app/views/item/show.gsp . Below is the GSP for
the item show view : <br>
<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><span style="font-weight: bold;">grails-app\</span><span
 style="font-weight: bold;">views\item\</span><b>show.gsp</b><b> </b></td>
    </tr>
    <tr>
      <td> <code> <br>
&lt;h2&gt; Detail of item&lt;/h2&gt;<br>
      <br>
&lt;table&gt;<br>
&lt;tbody&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;tr class="prop"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="name"&gt;Name:&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="value"&gt;${item.name}&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;
&lt;/tr&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp; &lt;tr class="prop"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="name"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Description:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="value"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
${<span style="color: rgb(0, 0, 153); font-weight: bold;">item.description</span>}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;
&lt;/tr&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp; &lt;tr class="prop"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="name"&gt;Imageurl:&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="value"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;img src="${<span style="color: rgb(0, 0, 153); font-weight: bold;">createLinkTo</span>(dir:'images',file:<span
 style="color: rgb(0, 0, 153); font-weight: bold;">item.imageurl</span>)}"
/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;
&lt;/tr&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp; &lt;tr class="prop"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="name"&gt;Price:&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="value"&gt;$
${item.price}&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;tr class="prop"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="name"&gt;Address:&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign="top"
class="value"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
${item?.address?.street1},
${<span style="color: rgb(0, 0, 153); font-weight: bold;">item?.address?.city</span>},&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
${item?.address?.state}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/td&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;
&lt;/tr&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&lt;/tbody&gt;<br>
&lt;/table&gt;&nbsp;&nbsp; </code> <br>
      <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
<code style="color: rgb(0, 0, 153); font-weight: bold;">${item.description}</code><br>
<div style="margin-left: 40px;">displays the value of the&nbsp; <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item 's </span></code><code
 style="color: rgb(0, 0, 153); font-weight: bold;">description</code><code><span
 style="color: rgb(0, 0, 153); font-weight: bold;"> </span></code>attribute.<br>
</div>
<code style="color: rgb(0, 0, 153); font-weight: bold;">&lt;img
src="${createLinkTo(dir:'images',file:item.imageurl)}" /&gt;</code><code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">&nbsp;</span></code>
<div style="margin-left: 40px;">generates an HTML
image tag for the <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item's imageurl</span></code>
<code><span style="color: rgb(0, 0, 153); font-weight: bold;"></span></code>attribute.
<br>
</div>
<code style="color: rgb(0, 0, 153); font-weight: bold;">
${item?.address?.city}</code>
<div style="margin-left: 40px;">displays the value of the&nbsp; <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">item's </span></code><code
 style="color: rgb(0, 0, 153); font-weight: bold;"><span
 style="font-family: mon;">address city</span></code><code><span
 style="color: rgb(0, 0, 153); font-weight: bold;"> </span></code>attribute.<br>
</div>
<code><span style="color: rgb(0, 0, 153); font-weight: bold;"></span></code><br>
The image below shows the resulting page for the url
http://host/catalog/item/show/105, which displays the item 105's
details:<br>
<br>
<div style="margin-left: 5px;">&nbsp;&nbsp;&nbsp;&nbsp;



<img alt="showpet.jpg" src="http://weblogs.java.net/blog/caroljmcdonald/archive/showpet.jpg" 
width="677" height="728" /> 
 <br>
</div>
<br>
<h4>Layouts</h4>
Grails <a href="http://grails.codehaus.org/Views+and+Layouts">layouts</a>&nbsp;
let you put common html on multiple views (for
example page headers,&nbsp; footers, sidebars).&nbsp; Default layout
templates are in the views layouts directory with a file name
corresponding to the controller, or you can associate a view with a
layout using the "layout" meta tag to your page:
<pre class="code-java">&lt;meta name=<span class="code-quote">"layout"</span> content=<span
 class="code-quote">"main"</span>&gt;</pre>
To add a title and parrot image to the
top of the Pet Catalog pages, I put this table in the
app\views\layouts\main.gsp&nbsp; layout: <span id="intelliTxt"></span><br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><span style="font-weight: bold;">app/views/layouts/</span><b>main.gsp</b></td>
    </tr>
    <tr>
      <td><span style="font-family: monospace;"><br>
&lt;table&gt;<br>
&nbsp; &lt;tr&gt;<br>
&nbsp;&nbsp; &lt;td&gt;Pet Catalog&lt;/td&gt;<br>
&nbsp;&nbsp; &lt;td&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;img
src="${createLinkTo(dir:'images',file:'pet_logo.jpg')}"/&gt;<br>
&nbsp;&nbsp; &lt;/td&gt;<br>
&nbsp;&lt;/tr&gt;<br>
&lt;/table&gt;<br>
      </span><code><br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
<br>
<br>
Conclusion<br>
This concludes the sample application which demonstrates how to work
with Groovy and Grails&nbsp; to page through a list
of&nbsp; Item <span style="font-weight: bold;">Model</span> objects
which are retrieved using Item
<span style="font-weight: bold;">Controller</span> action methods, and
displayed using Item <span style="font-weight: bold;">View</span> GSPs.<br>
<br>
<code></code>
<p><b>Setting Things Up</b><b> and Running the Sample code on </b><span
 style="font-weight: bold;">MySQL and Jetty:<br>
</span></p>
<ol>
  <li>If <a href="http://mysql.com/">MySQL</a>
is already installed, then download <a
 href="https://glassfish.dev.java.net/downloads/v2ur1-b09d.html">GlassFish
v2 UR1</a>. Otherwise you can also Download <a
 href="http://glassfish.java.net/">GlassFish v2 UR1</a>
and <a href="http://mysql.com/">MySQL</a> co-bundle
from the usual <a href="http://java.sun.com/javaee/downloads">Download
Page</a> (<a
 href="http://docs.sun.com/app/docs/doc/820-3797/ggkei?l=en&amp;q=mysql&amp;a=view">instructions</a>).
    <br>
    <br>
  </li>
  <li><a href="http://grails.codehaus.org/Download">Download </a>and
install Grails.<br>
    <br>
  </li>
  <li>Download the <a
 href="http://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=8159">sample
code</a> and extract its contents. You should now see the newly
extracted directory as <code>&lt;sample_install_dir&gt;/Catalog</code>,
where <code>&lt;sample_install_dir&gt;</code> is the directory where
you unzipped the sample package. For example, if you extracted the
contents to <code>C:\</code> on a Windows machine, then your newly
created directory should be at <code>C:\Catalog</code>.&nbsp; <br>
The
file&nbsp;
"<code>/Catalog/</code>grails-app/conf/<span style="font-weight: bold;">DataSource.groovy</span>"
is configured
for a <span style="font-weight: bold;">MySQL</span>
configuration.<br>
    <br>
  </li>
  <li>Start the MySQL database as follows:<br>
    <br>
    <ul>
      <li><b><code>&gt; mysqld_safe --user root
--console</code></b><br>
        <br>
      </li>
    </ul>
  </li>
  <li> Create the pet-catalog database:<br>
    <br>
    <ul>
      <li><b><code>&gt; mysqladmin
create petcatalog --user root</code></b><br>
        <a
 href="http://dev.mysql.com/doc/refman/5.0/en/batch-commands.html"><br>
        </a> </li>
    </ul>
  </li>
  <li><a
 href="http://dev.mysql.com/doc/refman/5.0/en/batch-commands.html">Create
the tables in the MySQL</a> pet-catalog database as follows:<br>
    <br>
    <ul>
      <li>
        <pre class="programlisting"><strong class="userinput"><code>shell</code></strong><strong
 class="userinput"><code>&gt; mysql</code></strong><strong
 class="userinput"><code> <em class="replaceable"><code></code></em></code></strong>pet-catalog<strong
 class="userinput"><code><em class="replaceable"><code></code></em> &lt; <em
 class="replaceable"><code></code></em></code></strong><code>catalog.sql</code></pre>
      </li>
      <li>using the file <code>catalog.sql </code>file from the <code>/Catalog</code>
directory. <code></code><br>
        <br>
      </li>
    </ul>
  </li>
  <li>Run the project as follows:<br>
in a command window in the /Catalog directory enter the command <br>
  </li>
  <li>
    <pre class="programlisting"><strong class="userinput"><code>&gt; grails run-app</code></strong></pre>
This will run the Application using the built-in Jetty Servlet engine.<br>
  </li>
</ol>
<blockquote>
When you run the project, your browser should display the Catalog home
page at http://localhost:8080/catalog/ . <br>
  <br>
  <br>
</blockquote>
<b>Run the Sample code on Glassfish:</b><br>
<ol>
  <li>Use the&nbsp; WAR file in <code>&lt;sample_install_dir&gt;/Catalog/Catalog.war
    </code>or Create a WAR file:<br>
    <ul>
      <li>
        <pre class="programlisting"><strong class="userinput"><code>&gt; grails war</code></strong></pre>
      </li>
    </ul>
  </li>
  <li>Copy the WAR file (<code>catalog-0.1.war</code>) to&nbsp; your
Glassfish installation "<code>domains/domain/autodeploy</code>"
directory. (Start Glassfish and MySQL if you haven't already)<br>
    <br>
  </li>
  <li>Enter the URL&nbsp; http://localhost:8080/<code>catalog-0.1</code>/&nbsp;
in
your browser, you should see the home page of the Sample
Application.<br>
  </li>
</ol>
<h2>References</h2>
<ul>
  <li>To learn how to build a Grails CRUD app see: <a
 href="http://blogs.sun.com/arungupta/entry/totd_30_crud_application_using">TOTD
#30: CRUD Application using Grails - Hosted on Jetty and HSQLDB</a><br>
  </li>
  <li>To learn how to run a Grails&nbsp; app on Glassfish and mySQL
see: <a
 href="http://weblogs.java.net/blog/arungupta/archive/2008/04/totd_31_crud_ap.html">TOTD
#31: CRUD Application using Grails - Hosted on GlassFish and MySQL</a></li>
  <li><a href="http://grails.codehaus.org/">Grails framework <br>
    </a></li>
  <li><a href="http://groovy.codehaus.org/">Groovy</a></li>
  <li><a
 href="http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html">MySQL
commands</a><br>
  </li>
</ul>
<br>
</body>
</html>

]]>

</content>
</entry>
<entry>
<title>speaking at Community One</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/04/speaking_at_com.html" />
<modified>2008-04-19T19:17:01Z</modified>
<issued>2008-04-19T19:16:55Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.9572</id>
<created>2008-04-19T19:16:55Z</created>
<summary type="text/plain">Kito Mann and I are speaking at  CommunityOne 2008 on: &quot;Examining
a Sample Application Built in Three different Ways: Java EE, Spring 2.5, and Seam 2.0&quot;</summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[<table border="0" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td class="body" valign="top">
      <div class="dayBox">
      <div class="entryBox"><br>
      <p class="entryTitle">Speaking at CommunityOne 2008</p>
      <p class="entryContent"> <a href="http://www.jsfcentral.com">
Kito Mann</a> and I&nbsp; are
speaking at <a href="http://developers.sun.com/events/communityone/">CommunityOne
2008</a> on: "Examining
a Sample Application Built in Three Ways: Java&#8482; Platform, Enterprise
Edition (Java EE Platform), Spring 2.5, and Seam 2.0 Deployed on the
GlassFish&#8482; Project". CommunityOne is the day before JavaOne (May
05), its free, and you can learn about a wide range of open source
projects. <br>
Our talk is May 05 12:25 - 13:20&nbsp;&nbsp;&nbsp; Moscone South -
Esplanade 305. Here is the abstract: <br>
This session looks at the implementation of the same web application
developed with three open source frameworks and highlights what was
done differently with each one. First it explains the implementation of
the sample application with JavaServer&#8482; Faces and Enterprise JavaBeans&#8482;
3.0 (EJB&#8482; 3.0) technology and the Java&#8482; Persistence API (JPA). Next it
looks at how this application was developed with JavaServer Faces
technology, the JPA, and Spring 2.5. Finally, it looks at this
application developed with JavaServer Faces and EJB 3.0 technology, the
JPA, and Seam 2.0. The presentation highlights differences in the
frameworks, such as the Seam context model for stateful components. All
three versions were deployed on GlassFish&#8482; project V2, and the source
code is available in my blog. <br>
      </p>
      <a href="http://technorati.com/tag/JavaOne"></a>
      <hr><img alt="C1_170x93_SpeakerB.gif"
 src="http://weblogs.java.net/blog/caroljmcdonald/archive/C1_170x93_SpeakerB.gif"
 height="93" width="170"><br>
      </div>
      </div>
      <br>
      <hr size="1"> </td>
      <td> <br>
      </td>
      <td colspan="5" bgcolor="#999999"> <br>
      </td>
    </tr>
  </tbody>
</table>]]>

</content>
</entry>
<entry>
<title>Metro Web Services Hands-on Lab at JavaOne 2008</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/04/metro_web_servi_1.html" />
<modified>2008-04-19T19:04:18Z</modified>
<issued>2008-04-19T17:02:44Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.9570</id>
<created>2008-04-19T17:02:44Z</created>
<summary type="text/plain">Fabian Ritzman, Martin Grebac and I  have developed a hands-on lab on Metro Web Services for JavaOne 2008.</summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Web Services and XML</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[<table border="0" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td class="body" valign="top">
      <div class="dayBox">
      <div class="entryBox"><br>
      <p class="entryTitle">Metro Hands-on Lab at JavaOne 2008</p>
      <p class="entryContent"> <a href="http://blogs.sun.com/ritzmann/">Fabian
Ritzman</a>, <a href="http://blogs.sun.com/mgrebac/">Martin Grebac</a>
and I&nbsp; have developed a hands-on lab on <a
 href="https://metro.dev.java.net/">Metro Web Services</a> for <a
 href="http://java.sun.com/javaone/sf/index.jsp">JavaOne 2008</a>. At
JavaOne <span style="font-weight: bold;">hands-on</span> labs, you
bring your own laptop, this allows you to easily take home and reuse
the stuff you learn in the lab. We have a step by step lab doc with
screenshots etc. that you can work
through to familiarize yourself with Metro. Fabian and I will briefly
explain and demonstrate the lab exercises, then you will complete them
on your laptop. There will be proctors to help with
any questions. Hope to see you there!&nbsp; You can find out more about
the lab here: <a
 href="https://www28.cplan.com/cc191/session_details.jsp?isid=296941&amp;ilocation_id=191-1&amp;ilanguage=english">https://www28.cplan.com/cc191/session_details.jsp?isid=296941&amp;ilocation_id=191-1&amp;ilanguage=english</a>
      </p>
      <p>The title of the lab is "Metro: Try Out Simple and
Interoperable
Web Services". Session ID is 3410. The lab takes place on Tuesday,
10:50 - 12:50.&nbsp; Here is the complete
abstract:</p>
      <p>Metro is a high-performance, extensible, easy-to-use web
service
stack. You can use it for every type of web service, from simple to
reliable, secured, and transacted web services that interoperate with
.NET services. Metro bundles stable versions of the JAX-WS (Java&#8482; API
for XML Web Services) reference implementation and WSIT (Web Services
Interoperability Technology).</p>
      <p>JAX-WS is a fundamental technology for developing SOAP-based
and
RESTful Java technology-based web services. WSIT enables secure,
reliable interoperability between Java technology-based web services
and Microsoft&#8217;s Windows Communication Foundation.</p>
      <p>This Hands-on Lab starts by developing a simple Metro web
service
and showing how to enhance this web service with Metro features such as
reliability and security. The next part of the lab enables a web
service client with Metro security features and has it interoperate
with the previously built service. The lab shows the ease of
development the NetBeans&#8482; 6.0 release provides for achieving this.</p>
      <p>The lab uses the NetBeans 6.0 release to modify and configure
both
the web service and the client, using Sun&#8217;s GlassFish&#8482; project
application server as the container. The lab uses WS-Reliability and
WS-Security as examples of Metro&#8217;s secure, reliable features.</p>
      <p>The lab comprises the following sections:</p>
Introduction to Metro
      <ul>
        <li>Develop and deploy a basic catalog web service to return a
list of catalog items </li>
        <li>Test the web service, using the Tester application provided
by the GlassFish project </li>
      </ul>
Metro Reliability
      <ul>
        <li>Enable reliability on the catalog web service, and examine
the messages </li>
        <li>Develop and deploy a Metro client for the catalog web
service, and configure the client for reliable access to the web
service </li>
      </ul>
Metro Security
      <ul>
        <li>Enable security on the catalog web service, and examine the
messages </li>
        <li>Configure the Metro client for the catalog web service
(from the previous exercise) for secure access to the secure web
service </li>
      </ul>
      <p>Prerequisites: some understanding of Servlets, XML, and SOAP</p>
      <p>At JavaOne, this lab will be presented in Hall E (Room# 132).</p>
      <p>Please bring your laptops to this lab as there no machines
provided in this room.</p>
System requirements:
      <ul>
        <li>Supported OS: Windows 2000/XP, Solaris 10/11, Linux </li>
        <li>Memory requirement: 768MB minimum, 1GB recommended </li>
        <li>Disk space requirement: 300 MB </li>
      </ul>
      <p>Software requirements:</p>
Also please make sure to install the following software prior to coming
to this lab:
      <ul>
        <li>JDK 5.0 or 6 </li>
        <li>NetBeans 6.0.1 with Web &amp; Java EE pack </li>
        <li>GlassFish V2 UR1 </li>
      </ul>
Tags: <a href="http://technorati.com/tag/Web+Services">Web Services</a>,
      <a href="http://technorati.com/tag/Metro">Metro</a>, <a
 href="http://technorati.com/tag/JavaOne">JavaOne</a>
      <hr><a href="http://java.sun.com/javaone"><img alt="170x93_Speaker_v4.gif" src="http://weblogs.java.net/blog/caroljmcdonald/archive/170x93_Speaker_v4.gif" width="170" height="93" /></a></div>
      </div>
      <br>
      <hr size="1"> </td>
      <td> <br>
      </td>
      <td colspan="5" bgcolor="#999999"> <br>
      </td>
    </tr>
  </tbody>
</table>]]>

</content>
</entry>
<entry>
<title>Steve Metsker</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/02/steve_metsker.html" />
<modified>2008-02-12T04:31:00Z</modified>
<issued>2008-02-12T04:31:00Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.9181</id>
<created>2008-02-12T04:31:00Z</created>
<summary type="text/plain">I&apos;m deeply saddened to share the news that Steve Metsker passed away
last Friday.</summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Community: Java User Groups</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[<br>
I'm deeply saddened to share the news that Steve Metsker passed away
last Friday. <br>
Steve Metsker was a member of and speaker for the Richmond JUG. Steve
was also the author of the following books: <a
 href="http://www.amazon.com/gp/pdp/profile/A13SCGNSXNI8HF/ref=cm_blog_pdp">Design
Patterns in C#, Design Patterns Java Workbook, Building Parsers in Java.</a><br>
<br>
Steve, his wife Alison, my husband and I enjoyed sharing our experiences about
working
and living in Switzerland. There was a memorial service Sunday which
was overflowing with people, many from the local IT community. He will
be greatly missed. <br>
<br>
The following is from his family:<br>
Steven John Metsker passed away on Friday, February
8, 2008 after a short illness with cancer. Aged 49, he is survived by
his loving wife, Alison, and their daughters, Sarah-Jane and Emma-Kate.
Having earned Engineering degrees from both the Colorado State
University and the University of Massachusetts, Steve was accomplished
in a profession for which he had great passion. Born in Colorado, he
also lived in Massachusetts, Maine, Texas, Switzerland, Kentucky,
England, and Richmond. He made many friends everywhere he went. A
loving and caring husband, father, brother, son, friend, and colleague,
he was also a humble and wise mentor. He was a positive and loving
influence on all of us, who will miss him dearly. In lieu of flowers
please send donations to St. Baldrick's fund raising program for
childhood cancer or to Our Lady's Children's Hospital, Dublin Ireland. <br>
<br>]]>

</content>
</entry>
<entry>
<title>Dynamic Ajax table example using jMaki and Java Persistence APIs on Glassfish</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/02/dynamic_ajax_ta.html" />
<modified>2008-02-12T04:31:09Z</modified>
<issued>2008-02-08T18:52:17Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.9165</id>
<created>2008-02-08T18:52:17Z</created>
<summary type="text/plain">This Sample Catalog app demonstrates the usage of the Java Persistence APIs to implement server side pagination (recommended for large sets of data), and  jMaki to get and display the results in a dynamic Ajax table</summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Web Applications</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>Sample Application using jMaki and the Java Persistence APIs</title>
</head>
<body>
<h2>a Dynamic Ajax table example using jMaki
and Java Persistence APIs on Glassfish <br>
</h2>
<br>
This Sample Catalog app demonstrates the usage of the Java
Persistence APIs to implement server side pagination (recommended for
large sets of data), and&nbsp; jMaki to get and display the results in
a dynamic Ajax table.<br>
<br>
<a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555">Download
the jMaki Sample Application Code</a><br>
<br>
<a href="https://ajax.dev.java.net/" target="_blank"></a><a
 href="https://ajax.dev.java.net/">jMaki</a> is an Ajax framework that
provides a lightweight model for creating JavaScript centric
Ajax-enabled web applications. jMaki provides wrapped<a
 href="http://developers.sun.com/docs/web/swdp/r1/tutorial/doc/p13.html">
widgets that can be used as JavaServer Pages tags</a>, as JavaServer
Faces components, within a Phobos application, or with PHP. This sample
applicaton uses jMaki with JavaServer Pages. <br>
<br>
<h3>Explanation of the usage of jMaki and the Java Persistence
APIs in a sample Catalog Application</h3>
The image below shows the Customer Listing page, which allows the user
to
page through a list of customers. <br>
<br>
<div style="margin-left: 40px;">
<img alt="pagingtable.jpg" src="http://weblogs.java.net/blog/caroljmcdonald/pagingtable.jpg"
 width="453" height="369" />

<br>
</div>
<br>
<h4>jMaki dataTable widget</h4>
With&nbsp; jMaki and JavaServer Pages, you can easily include wrapped
widgets
from ajax toolkits into a JavaServer Page as a custom JSP tag. <a
 href="http://www.netbeans.org/kb/55/framework-adding-support.html">With
the Netbeans jMaki plugin you can drag&nbsp; jMaki widgets from the
Palette into a JSP</a>. jMaki standardizes widget data and event models
to simplify the
programming model and to simplify interactions between widgets.<br>
<br>
The sample application's index.jsp page uses a jMaki <code
 style="font-weight: bold;">yahoo.dataTable</code>
widget to display a&nbsp; list of
customers in a dynamic table. <br>
<br>
The jMaki table widgets (there is also a jMaki dojo table
widget) are useful when you want to show a set of
results in tabular data on a web page.&nbsp; Table widgets provide
sortable columns, row selection, and they can
be updated using jMaki publish subscribe events.<br>
<br>
In the <code style="color: rgb(0, 102, 0); font-weight: bold;">List</code>.jsp
web page the dataTable is defined as shown below:&nbsp;&nbsp; (Note: <span
 style="color: rgb(204, 0, 0); font-weight: bold;">Red</span> colors
are for <span style="color: rgb(204, 0, 0); font-weight: bold;">jMaki</span>
tags,&nbsp;
and <span style="color: rgb(0, 102, 0); font-weight: bold;">Green</span>
for <span style="color: rgb(0, 102, 0); font-weight: bold;">my code</span>
or <span style="color: rgb(0, 102, 0); font-weight: bold;">variables</span>)<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from:&nbsp; </b><code
 style="color: rgb(0, 102, 0); font-weight: bold;"><span
 style="color: rgb(0, 0, 0);">index.jsp</span></code></td>
    </tr>
    <tr>
      <td> <code><span style="font-weight: bold;"><br>
&lt;jsp:useBean id="<span style="color: rgb(0, 102, 0);">catalogBean</span>"
scope="session" </span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
class="<span style="color: rgb(0, 102, 0);">service.Catalog</span>"
/&gt;</span><br>
      <br>
      <span style="color: rgb(204, 0, 0); font-weight: bold;">&lt;a:widget
name="yahoo.dataTable"</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">subscribe=</span>"<span
 style="color: rgb(0, 102, 0); font-weight: bold;">/datatable</span>"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="font-weight: bold; color: rgb(204, 0, 0);">publish=</span>"<span
 style="color: rgb(0, 102, 0); font-weight: bold;">/datatable</span>"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">value=</span><span
 style="font-weight: bold;">"{columns : [</span><br
 style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{ label : </span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">'Company', id :
'name'</span><span style="font-weight: bold;">},</span><br
 style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{ label :</span><span style="color: rgb(0, 102, 0); font-weight: bold;">'City',
id : 'city'</span><span style="font-weight: bold;">},</span><br
 style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{ label : </span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">'State', id : 'state'</span><span
 style="font-weight: bold;">},</span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{ label : </span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">'Zip', id : 'zip'</span><span
 style="font-weight: bold;">}</span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
],</span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
rows : ${</span><span style="color: rgb(0, 102, 0); font-weight: bold;">catalogBean.customersJSON</span><span
 style="font-weight: bold;">}}" /&gt;</span><br>
      <br>
      </code></td>
    </tr>
  </tbody>
</table>
<br>
To determine the data format and events for the
table you can refer to the&nbsp; <a
 href="http://wiki.java.net/bin/view/Projects/jMakiTableDataModel">jMaki
Table Data Model</a> or look at
the widget.json file for the table widget. This file is located in the
resources/yahoo/dataTable directory.<br>
The <code style="color: rgb(204, 0, 0); font-weight: bold;"
 class="cCode">value</code> attribute references the data to be
included
in the table.&nbsp; The data for the table should be a
<a href="http://www.json.org/">JSON</a> object containing an object of
columns and an array of row arrays. The column names need a unique id
which is then used in the data to associate it with a given row. An
example for a table of companys is shown below:<br>
<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from:&nbsp; </b><code
 style="color: rgb(0, 102, 0); font-weight: bold;"><span
 style="color: rgb(0, 0, 0);">widget.json</span></code></td>
    </tr>
    <tr>
      <td> <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;"></span>{<br>
&nbsp;'columns':[<br>
&nbsp;&nbsp;&nbsp;&nbsp; {'label' :'Company', 'id' : 'name'},<br>
&nbsp;&nbsp;&nbsp;&nbsp; {'label':'City', 'id' : 'city'}<br>
&nbsp;],<br>
&nbsp;'rows':[<br>
&nbsp;&nbsp;&nbsp;&nbsp; {'name' : 'Sun Microsystems', 'city' : 'Santa
Clara'},<br>
      </code><code>&nbsp;&nbsp;&nbsp;&nbsp; {'name' : 'IBM', 'city' :
'Raleigh'}</code><code><br>
&nbsp;]<br>
}<br>
      <br>
      </code></td>
    </tr>
  </tbody>
</table>
<br>
<br>
The <code><span style="font-weight: bold; color: rgb(204, 0, 0);">publish
</span></code><code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">subscribe</span></code>
attributes specify a topic that publish and subscribe events will be
sent to. Publish and subscribe events can be used to tie widgets
together (more on this later).<br>
<br>
The dataTable's <code><span
 style="font-weight: bold; color: rgb(204, 0, 0);">value</span></code> <code><span
 style="font-weight: bold;">rows : ${</span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">catalogBean.customersJSON</span><span
 style="font-weight: bold;">}&nbsp;</span></code> calls the <code><span
 style="font-weight: bold;"></span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">getCustomersJSON</span><span
 style="font-weight: bold;"></span></code> method
of the <code><span style="color: rgb(0, 102, 0); font-weight: bold;">catalogBean</span></code>
class:<br>
<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Catalog</span></code><b>.java</b></td>
    </tr>
    <tr>
      <td> <code><span
 style="font-weight: bold; color: rgb(204, 0, 0);"></span>public class <span
 style="color: rgb(0, 102, 0); font-weight: bold;">Catalog</span>
{<br>
&nbsp;&nbsp; <br>
&nbsp;public List&lt;Customer&gt; <span
 style="font-weight: bold; color: rgb(0, 102, 0);">getCustomers()</span>
throws Exception {<br>
&nbsp;&nbsp; <span style="font-weight: bold; color: rgb(0, 0, 153);">EntityManager</span>
em
= getEntityManager();<br>
&nbsp;&nbsp; <span style="font-weight: bold; color: rgb(0, 0, 153);">Query
q = em.createQuery(</span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"select object(o) from Customer as o");</span><br
 style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp; <span
 style="color: rgb(0, 0, 153);">q.setMaxResults(batchSize);</span></span><br
 style="font-weight: bold; color: rgb(0, 0, 153);">
      <span style="font-weight: bold; color: rgb(0, 0, 153);">&nbsp;&nbsp;
q.setFirstResult(firstItem);</span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp; return <span
 style="color: rgb(0, 0, 153);">q.getResultList();</span></span><br>
&nbsp;}&nbsp;&nbsp; <br>
      <br>
&nbsp;public <span style="font-weight: bold;">JSONArray</span> <span
 style="font-weight: bold; color: rgb(0, 102, 0);">getCustomersJSON()</span>
throws Exception {<br>
&nbsp;&nbsp; <span style="font-weight: bold;">JSONArray</span> <span
 style="font-weight: bold;">customersJSON = new JSONArray();</span><br>
&nbsp;&nbsp; List&lt;Customer&gt; customers = <span
 style="color: rgb(0, 102, 0); font-weight: bold;">getCustomers();</span><br>
&nbsp;&nbsp; for (Customer customerData : customers) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">JSONArray
customerJSON</span> = <span
 style="color: rgb(0, 102, 0); font-weight: bold;">customerData.toJSON();</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">customersJSON.put(customerJSON);</span><br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; return <span style="font-weight: bold;">customersJSON;</span><br>
&nbsp;}<br>
      <span style="font-weight: bold;"></span><span
 style="color: rgb(0, 0, 153); font-weight: bold;"><span
 style="font-family: monospace;"><span style="color: rgb(0, 0, 0);"></span></span></span><br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
<h4>Java Persistence Query API <br>
</h4>
The <code><span style="color: rgb(0, 102, 0); font-weight: bold;">Catalog&nbsp;</span></code><code>getCustomersJSON()&nbsp;</code>
uses the Java Persistence API <span style="color: rgb(204, 0, 0);"></span><code><span
 style="color: rgb(204, 0, 0);"><span style="font-weight: bold;"></span></span></code><code
 style="color: rgb(0, 0, 153);"><span style="font-weight: bold;">Query</span></code><code><span
 style="color: rgb(204, 0, 0); font-weight: bold;"> </span></code>object
to return a list of <code
 style="color: rgb(0, 102, 0); font-weight: bold;">customers</code>, a <a
 href="http://www.json.org/javadoc/org/json/JSONArray.html">JSONArray</a>&nbsp;
object is used to return the list in JSON format.&nbsp; The Java
Persistence <a
 href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html">Query
APIs</a> are used to create and execute queries that can return a
list of results.&nbsp; The JPA Query interface provides
support for pagination via the setFirstResult() and setMaxResults()
methods: <span style="font-weight: bold; color: rgb(0, 0, 0);">query.</span><b
 style="color: rgb(0, 0, 0);">setMaxResults</b>(int&nbsp;maxResult)
sets the maximum number of results to retrieve.<b><span
 style="font-family: mon;"> <span style="color: rgb(0, 0, 0);">query.</span></span><span
 style="color: rgb(0, 0, 0);">setFirstResult</span></b>(int&nbsp;startPosition)
sets the position of the first result to retrieve.
<br>
<br>
In the code below, we show the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Customer</span></code>
entity class which maps to the&nbsp; CUSTOMER table that stores the
customer instances. This is a
typical Java Persistence entity object. There are two requirements for
an entity:<br>
<ol>
  <li>annotating the class with an <code><span
 style="font-weight: bold; color: rgb(0, 0, 153);">@Entity</span></code>
annotation. <br>
  </li>
  <li> annotating the primary key identifier with <code
 style="font-weight: bold; color: rgb(0, 0, 153);">@Id</code><code
 style="color: rgb(0, 0, 0);"></code> </li>
</ol>
Because the fields name, description.... are basic mappings from the
object fields to columns of the same name in the database table, they
don't have to be annotated.&nbsp; <br>
For more information on Netbeans and JPA see<a
 href="http://www.apress.com/book/bookDisplay.html?bID=10093"></a> <a
 href="http://www.netbeans.org/kb/55/persistence.html">basics of
developing a web application using Java&#8482; Persistence API.</a><br>
<br>
<a name="code-example-2" target="bpcatalog"></a>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Customer</span></code><b>.java</b></td>
    </tr>
    <tr>
      <td> <code><br>
      <span style="font-weight: bold; color: rgb(0, 0, 153);">@Entity</span><br
 style="color: rgb(0, 0, 0);">
      <span style="font-weight: bold; color: rgb(0, 0, 0);"></span><span
 style="color: rgb(0, 0, 0);"></span><br style="color: rgb(0, 0, 0);">
      <span style="color: rgb(0, 0, 0);">public class </span><span
 style="font-weight: bold; color: rgb(0, 102, 0);"><span
 style="font-family: monospace;">Customer</span></span><span
 style="color: rgb(0, 0, 0);">
implements Serializable {</span><br style="color: rgb(0, 0, 0);">
      <br style="color: rgb(0, 0, 0);">
      <span style="color: rgb(0, 0, 0);">&nbsp; &nbsp; </span></code><code
 style="font-weight: bold; color: rgb(0, 0, 153);">@Id</code><code
 style="color: rgb(0, 0, 0);">
&nbsp; <br>
&nbsp;&nbsp;&nbsp; private Integer customerId;</code><code
 style="color: rgb(0, 0, 0);"></code><code style="color: rgb(0, 0, 0);"><br>
&nbsp;&nbsp;&nbsp; private String name;<br>
&nbsp;&nbsp;&nbsp; private String addressline1;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private String city; &nbsp; <br>
&nbsp;&nbsp;&nbsp; private String state;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private String zip; </code><code
 style="color: rgb(0, 0, 0);"></code><br style="color: rgb(0, 0, 0);">
      <code style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; public </code><code style="color: rgb(0, 102, 0);"><span
 style="font-weight: bold;"><span style="font-family: monospace;">Customer</span></span></code><code
 style="color: rgb(0, 0, 0);">() { }<br>
&nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; public String getName() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return name;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; public void setName(String name) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.name = name;<br>
&nbsp;&nbsp;&nbsp; }</code><code><span style="color: rgb(0, 0, 0);"></span><br
 style="color: rgb(0, 0, 0);">
      <br style="color: rgb(0, 0, 0);">
      <span style="color: rgb(0, 0, 0);">&nbsp; &nbsp; ...<br>
&nbsp; &nbsp; public JSONArray <span
 style="font-weight: bold; color: rgb(0, 102, 0);">toJSON()</span>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JSONArray thisJSON = new
JSONArray();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thisJSON.put(this.getName());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thisJSON.put(this.getCity());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thisJSON.put(this.getState());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thisJSON.put(this.getZip());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return thisJSON;<br>
&nbsp;&nbsp;&nbsp; } </span><br style="color: rgb(0, 0, 0);">
      <span style="color: rgb(0, 0, 0);">}&nbsp;&nbsp;&nbsp; </span><br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
I added the<code><span style="color: rgb(0, 0, 0);"><span
 style="font-weight: bold;"> toJSON() </span></span></code>method to
the <code><span style="font-weight: bold; color: rgb(0, 0, 0);"><span
 style="font-family: monospace;">Customer</span></span><span
 style="color: rgb(0, 0, 0);"> </span></code>to return a JSON
representation of the <code><span
 style="font-weight: bold; color: rgb(0, 0, 0);"><span
 style="font-family: monospace;">Customer</span></span></code> entity. <code><span
 style="color: rgb(0, 0, 0);"><span style="font-weight: bold;"></span></span></code><br>
<h4>jMaki Publish Subscribe events&nbsp;<br>
</h4>
jMaki publish subscribe events tie widgets actions together. The sample
app
uses two jMaki <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">yahoo.button</span> </code>widgets
which <span style="font-weight: bold;">publish</span> to the
<code><span style="color: rgb(0, 102, 0); font-weight: bold;">/button/previous</span>,
</code><code style="color: rgb(0, 102, 0); font-weight: bold;">/button/next</code><code>&nbsp;</code><code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">topics</span></code><span
 style="font-weight: bold;">
</span>when the respective button is clicked:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code
 style="color: rgb(0, 102, 0); font-weight: bold;">List<span
 style="color: rgb(0, 0, 0);">.jsp</span></code></td>
    </tr>
    <tr>
      <td> <code><br>
      <span style="font-weight: bold; color: rgb(204, 0, 0);">&lt;a:widget
name="yahoo.button"</span> value="{label : '&lt;&lt;', <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
action : {<span style="color: rgb(204, 0, 0); font-weight: bold;">topic</span>
: '<span style="color: rgb(0, 102, 0); font-weight: bold;">/button/previous</span>'}}"
/&gt;<br>
      <br style="font-weight: bold;">
      <span style="color: rgb(204, 0, 0); font-weight: bold;">&lt;a:widget
name="yahoo.button"</span> value="{label : '&gt;&gt;', <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
action : {<span style="color: rgb(204, 0, 0); font-weight: bold;">topic</span>
: '<span style="color: rgb(0, 102, 0); font-weight: bold;">/button/next</span>'}}"
/&gt;<br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
Events in jMaki are handled by <a
 href="https://ajax.dev.java.net/introGlue.html">jMaki Glue</a> , which<a
 href="https://ajax.dev.java.net/introGlue.html"></a> allows JavaScript
components to talk to each
other. You put function listeners which Subscribe to topics that your
widgets Publish to in a file called glue.js (to read more about this
see&nbsp;<a href="https://ajax.dev.java.net/introGlue.html">A practical
guide to jMaki Events</a> ). <br>
<br>
<span style="font-weight: bold;">Connecting the listener to the handler</span><br>
&nbsp;
<br>
The listener handler for the&nbsp; <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">/button/next </span></code><code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">topic </span></code><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;"></span></code>is
shown below. First you declare the topic to listen to and then the
listener function which will handle the notification. The <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">/button/next </span></code>listener
handler&nbsp; increments the page number and then calls the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">getNextPage</span></code>
funtion. <br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code style="color: rgb(204, 0, 0);"><span
 style="font-weight: bold;">glue.js</span></code><b></b></td>
    </tr>
    <tr>
      <td><code>var page= 0;<br>
      <br>
      <span style="color: rgb(204, 0, 0); font-weight: bold;">jmaki.subscribe</span>("<span
 style="color: rgb(0, 102, 0); font-weight: bold;">/button/next</span>",
function(args) {<br>
&nbsp;&nbsp;&nbsp; page =page + 1;<br>
&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(0, 102, 0); font-weight: bold;">getNextPage</span>(page);<br>
});<br>
      <br>
      <span style="font-weight: bold; color: rgb(204, 0, 0);">jmaki.subscribe</span>("<span
 style="color: rgb(0, 102, 0); font-weight: bold;">/button/previous</span>",
function(args) {<br>
&nbsp;&nbsp;&nbsp; page =page - 1;<br>
&nbsp;&nbsp;&nbsp; if (page &lt; 0) page = 0;<br>
&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(0, 102, 0); font-weight: bold;">getNextPage</span>(page);<br>
});<br>
      <br>
function <span style="color: rgb(0, 102, 0); font-weight: bold;">getNextPage</span>(page)
{<br>
&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">jmaki.doAjax</span>({method:
"POST",<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">url:</span> "<span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogService</span>?page="+encodeURIComponent(page),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">callback :</span>
function(<span style="color: rgb(204, 0, 0); font-weight: bold;">req</span>)
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(0, 102, 0); font-weight: bold;">customers</span>
= eval(<span style="color: rgb(204, 0, 0); font-weight: bold;">req.responseText</span>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="font-weight: bold; color: rgb(204, 0, 0);">jmaki.publish</span>("<span
 style="color: rgb(0, 102, 0); font-weight: bold;">/datatable/</span><span
 style="color: rgb(204, 0, 0); font-weight: bold;">clear</span>", { });<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">jmaki.publish</span>("<span
 style="font-weight: bold; color: rgb(0, 102, 0);">/datatable/</span><span
 style="color: rgb(204, 0, 0); font-weight: bold;">addRows</span>", <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{ <span style="color: rgb(204, 0, 0); font-weight: bold;">value</span>
: <span style="color: rgb(0, 102, 0); font-weight: bold;">customers</span>}
);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; });&nbsp;&nbsp;&nbsp;&nbsp; <br>
}<br>
      </code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code></code><code></code><br>
      </td>
    </tr>
  </tbody>
</table>
<br>
The <code><span style="color: rgb(0, 102, 0); font-weight: bold;">getNextPage</span></code>
function uses&nbsp; <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">jmaki.doAjax</span></code>,
<code><span style="color: rgb(204, 0, 0); font-weight: bold;"></span></code>which
provides an easy way to make an&nbsp; XMLHttpRequest, to call the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogService</span></code>
servlet passing the page number as a URI parameter.&nbsp; The&nbsp; <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">callback </span></code>function
uses&nbsp; <code>eval</code> to convert the XMLHttpRequest response
into a JSON object. Then&nbsp; <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">jmaki.publish</span></code>
is called to publish the returned <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">customers</span></code>
JSON object to the <code><span
 style="font-weight: bold; color: rgb(0, 102, 0);">/datatable/</span><span
 style="color: rgb(204, 0, 0); font-weight: bold;">addRows </span></code>topic.<br>
<br>
The <code><span style="color: rgb(204, 0, 0); font-weight: bold;">yahoo.dataTable
widget </span></code>subscrib<span style="font-family: mon;">es to the</span><code><span
 style="color: rgb(204, 0, 0);"></span></code><code><span
 style="color: rgb(204, 0, 0); font-weight: bold;"> </span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">datatable</span> </code>topic.<br>
Subscribe events allow you to manipulate a given instance of a widget.
The event names are appended to the the subscribe topic name following
a "/". For example&nbsp; "<code><span
 style="font-weight: bold; color: rgb(0, 102, 0);">/datatable/</span><span
 style="color: rgb(204, 0, 0); font-weight: bold;">addRows</span></code>"
will call the <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">yahoo.dataTable </span></code><a
 href="http://wiki.java.net/bin/view/Projects/jMakiTableDataModel">addRows</a>
function which will add the&nbsp; payload value passed to the widget to
the the table. This will cause the&nbsp; returned <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">customers</span></code>
JSON object to be displayed in the table on the html page. <br>
<br>
This <code><span style="color: rgb(0, 102, 0); font-weight: bold;">CatalogServlet
</span></code><code>processRequest </code><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;"></span></code>
method is defined as shown below:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogBean</span></code><b>.java</b></td>
    </tr>
    <tr>
      <td> <br>
      <code>public class <span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogServlet</span>
extends HttpServlet {<br>
      <br>
protected void processRequest(HttpServletRequest request, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletResponse response)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws ServletException,
IOException {<br>
      <br>
&nbsp;&nbsp; <span style="color: rgb(0, 102, 0); font-weight: bold;">Catalog</span>
catalog = new Catalog();<br>
&nbsp;&nbsp; response.setContentType("text/plain;charset=UTF-8");<br>
&nbsp;&nbsp; PrintWriter out = response.getWriter();<br>
&nbsp;&nbsp; int page =<br>
&nbsp; &nbsp;&nbsp; Integer.parseInt(request.getParameter("page"));<br>
      </code><code></code><code><br>
&nbsp;&nbsp; <span style="font-weight: bold;">JSONArray array</span> =
      <span style="color: rgb(0, 102, 0); font-weight: bold;">catalog.getNextCustomersJSON(page)</span>;<br>
&nbsp;&nbsp; out.println(<span style="font-weight: bold;">array.toString()</span>);<br>
&nbsp;&nbsp; out.close();<br>
} <br>
      </code> <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
The <code><span style="color: rgb(0, 102, 0); font-weight: bold;">CatalogServlet
</span></code>simply calls the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Catalog </span></code>bean
to get the next list of results from the database like we saw in the
previous code. The <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogServlet </span></code>then
returns the resulting <code><span style="font-weight: bold;">JSONArray
</span></code>as a text string.<br>
<code><span style="color: rgb(0, 102, 0); font-weight: bold;"></span></code><br>
Conclusion<br>
This concludes the sample application which demonstrates the usage of
the Java
Persistence APIs and jMaki in a dynamic Ajax table example.<br>
<br>
<h3><span style="font-weight: bold;">Configuration of the Application
for jMaki, JPA, Netbeans 6 and Glassfish V2<br>
</span></h3>
<ul>
  <li><a href="http://download.netbeans.org/netbeans/6.0/final/">Download</a>
and install NetBeans 6 bundled with GlassFish V2<br>
  </li>
  <li>Alternatively you can&nbsp; <a
 href="https://glassfish.dev.java.net/public/downloadsindex.html">Download</a>
and install GlassFish V2 separately. </li>
  <li><a href="http://labs.jboss.com/jbossseam/download/index.html"></a>Download
and install the <a
 href="http://www.netbeans.org/kb/55/framework-adding-support.html">jMaki
plug-in</a> in the NetBeans update center. </li>
</ul>
<br>
<p><b>Open and Run the Sample code:</b>
</p>
<ol>
  <li>Download the <a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555">sample
code</a> and extract its contents. You should now see the newly
extracted directory as <code>&lt;sample_install_dir&gt;/jmakiPagingJPA</code>,
where <code>&lt;sample_install_dir&gt;</code> is the directory where
you installed the sample package. For example, if you extracted the
contents to <code>C:\</code> on a Windows machine, then your newly
created directory should be at <code>C:\jmakiPagingJPA</code>.<br>
    <br>
  </li>
  <li>Start the NetBeans IDE. Click Open Project in the File menu and
select the <code>jmakiPagingJPA</code> directory you just unzipped. <br>
    <br>
  </li>
  <li>Build the project as follows:<br>
    <br>
    <ul>
      <li>Right click the <code>jmakiPagingJPA</code> node in the
Projects window.<br>
      </li>
      <li>Select Clean and Build Project. <br>
        <br>
      </li>
    </ul>
  </li>
  <li>Run the project as follows:<br>
    <br>
    <ul>
      <li>Right click the <code>jmakiPagingJPA</code> node in the
Projects window.<br>
      </li>
      <li>Select Run Project.<br>
      </li>
    </ul>
  </li>
</ol>
<blockquote>
When you run the project, your browser should display the opening page
of the Sample Application (at
http://localhost:8080/jmakiPagingJPA/). </blockquote>
<br>
<br>
<span style="font-weight: bold;">If you want to create your own jMaki
application:</span>
<ul>
  <li>check out Arun Gupta's <a
 href="http://blogs.sun.com/arungupta/entry/dynamic_data_in_jmaki_widgets">blog</a>
and screencasts.<a
 href="http://blogs.sun.com/arungupta/entry/dynamic_data_in_jmaki_widgets"></a><br>
  </li>
</ul>
<h2>References:</h2>
<ul>
  <li><a href="https://ajax.dev.java.net/">jMaki project</a><br>
  </li>
  <li><a href="https://ajax.dev.java.net/book/toc.html">jMaki book</a></li>
  <li><a
 href="http://blogs.sun.com/arungupta/entry/dynamic_data_in_jmaki_widgets">Dynamic
Data in jMaki Widgets Using JPA</a><br>
  </li>
  <li><a href="http://www.netbeans.org/kb/55/persistence.html">basics
of
developing a web application using Java&#8482; Persistence API.</a></li>
  <li><a href="https://glassfish.dev.java.net/javaee5/persistence/"
 target="bpcatalog">Java
Persistence reference page on GlassFish Project&nbsp;</a></li>
  <li><a href="http://java.sun.com/javaee/5/docs/tutorial/doc/">Java
EE tutorial,&nbsp; for good tutorial on JPA</a> </li>
  <li><a href="http://www.apress.com/book/bookDisplay.html?bID=10093">Pro
EJB 3: Java Persistence API book</a></li>
</ul>
<br>
<br>
<br>
</body>
</html>
]]>

</content>
</entry>
<entry>
<title>Sample Application using JSF, Seam 2.0, and Java Persistence APIs on Glassfish V2</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/01/sample_applicat_4.html" />
<modified>2008-02-12T04:31:21Z</modified>
<issued>2008-01-28T03:58:05Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.9079</id>
<created>2008-01-28T03:58:05Z</created>
<summary type="text/plain">I updated my previous example using JavaServer Faces, EJB, the Java Persistence APIs, and Seam 1.2 on Glassfish v1,  to use Seam 2.0 on Glassfish V2. </summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[
<h2>Sample Application using JSF, Seam 2.0,
and Java Persistence APIs on Glassfish V2<br>
</h2>
<br>
I updated&nbsp; this example&nbsp; <a
 href="http://weblogs.java.net/blog/caroljmcdonald/archive/2007/07/sample_applicat_1.html">Sample
Store Catalog app using JavaServer
Faces, EJB, the Java Persistence APIs, and
Seam 1.2 on Glassfish v1</a>&nbsp; to use Seam 2.0 on Glassfish V2. The
Seam jar files needed to run on Glassfish have changed in Seam 2.0,
(thanks to&nbsp;<a href="http://weblogs.java.net/blog/cayhorstmann/">Cay
Horstmann</a> for pointing out which Seam 2.0 jars are needed)&nbsp;
nothing else in the example needs changing.&nbsp; I also successfully
tested Brian
Leonard's <a
 href="http://weblogs.java.net/blog/bleonard/archive/2007/06/seam_refresh_1.html">Seam
Refresh</a> example with the Seam 2.0 jars, listed below, on Glassfish
V2. <br>
<br>
<a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555">Download
the Seam Sample Application Code</a><br>
<br>
<br>
<h3><span style="font-weight: bold;">Configuration of the Application
for Seam 2.0, JSF, JPA, running on Glassfish V2<br>
</span></h3>
First I recommend reading  Brian Leonard's
blog <a
 href="http://weblogs.java.net/blog/bleonard/archive/2007/06/seam_refresh_1.html">Seam
Refresh</a> .&nbsp; I will <span style="font-weight: bold;">summarize and update </span>
those steps here:<br>
<br>
<ul>
  <li><a href="http://download.netbeans.org/netbeans/6.0/final/">Download</a>
and install NetBeans 6 bundled with GlassFish V2<br>
  </li>
  <li>Alternatively you can&nbsp; <a
 href="https://glassfish.dev.java.net/public/downloadsindex.html">Download</a>
and install GlassFish V2 separately. </li>
  <li><a href="http://labs.jboss.com/jbossseam/download/index.html">Download</a>
and extract Seam 2.0<br>
  </li>
  <li><a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555">Download
the Seam 2.0&nbsp; Sample Application Code</a></li>
</ul>
<h4>To Open and Test Run the seampagination Project:</h4>
<ul>
  <li>Use the Resolve Reference Problems dialog to map the ejb and web
modules to their
project, which are subdirectories beneath the seampagination
directory.</li>
  <li>After the references are resolved, right-click the seampagination
project and select Open Required Projects.</li>
  <li><a
 href="http://weblogs.java.net/blog/bleonard/archive/2007/06/seam_refresh_1.html"></a>Right-click
the seampagination-EJBModule and select Resolve
Reference
Problems:
    <ul>
      <li>browse to the Seam lib directory and select jboss-seam.jar
and
select Open. This should resove the reference to the following jars:
jboss-seam.jar, hibernate.jar, hibernate-validator.jar,
hibernate-annotations.jar, hibernate-commons-annotations.jar,
javassist.jar, dom4j.jar, commons-logging.jar<br>
      </li>
    </ul>
  </li>
  <li>Right-click the seampagination-WebModule and select Resolve
Reference
Problems:
    <ul>
      <li>Browse to the seampagination-ejb directory which is a
sub-directory below the seampagination directory and select Open
Project
Folder.</li>
    </ul>
    <ul>
      <li>Browse to the&nbsp; jboss-seam-ui.jar found in Seam lib
directory&nbsp; and select Open Project
Folder.&nbsp; This should resove the reference to the following jars:
jboss-seam-ui.jar and jboss-el.jar.<br>
      </li>
    </ul>
  </li>
</ul>
<span style="font-weight: bold;">If you want to create your own Java EE
application using Seam 2.0 on Glassfish V2 with Netbeans from scratch</span>
(read the steps in Brian Leonard's
blog <a
 href="http://weblogs.java.net/blog/bleonard/archive/2007/06/seam_refresh_1.html">Seam
Refresh</a> <span style="font-weight: bold;">but use the SEAM 2.0 jars listed here </span> here):
<ul>
  <li><a
 href="http://weblogs.java.net/blog/bleonard/archive/2007/06/seam_refresh_1.html"></a>Use
Netbeans to create a new Enterprise Application</li>
  <li>Right-click the Libraries node of the EJBModule project , choose
Add Jar&nbsp; and add these jars:
    <ul>
      <li><span class="style1"></span>Seam \lib\jboss-seam.jar</li>
      <li>Seam \lib<span class="style1">\hibernate.jar</span></li>
      <li>Seam \lib<span class="style1">\</span><span class="style1">hibernate-validator.jar</span></li>
      <li>Seam \lib<span class="style1">\</span><span class="style1"></span><span
 class="style1">hibernate-annotations.jar <br>
        </span></li>
      <li>Seam \lib<span class="style1">\</span><span class="style1"></span><span
 class="style1">hibernate-commons-annotations.jar</span></li>
      <li>Seam \lib\javassist.jar<br>
      </li>
      <li>Seam \lib\dom4j.jar</li>
      <li>Seam \lib\commons-logging.jar</li>
    </ul>
  </li>
  <li>Right-click the Libraries node of the WebModule project ,&nbsp;
choose Add Jar&nbsp; and add these jars:
    <ul>
      <li>your ejbModule</li>
      <li>Seam \lib\jboss-seam-ui.jar</li>
      <li>Seam \lib\jboss-el.jar<br>
      </li>
    </ul>
  </li>
  <li>create an empty seam.properties file in the
seampagination-EJBModule <strong>src\conf </strong>Folder.</li>
  <li>add&nbsp; the following phase listener to your faces-config.xml
file under webpages web-inf:<br>
    <pre><span class="xml-tag">&lt;<span style="color: rgb(204, 0, 0);">lifecycle</span></span><span
 class="xml-tag">&gt;</span><br>        <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">phase-listener</span></span><span
 class="xml-tag">&gt;</span><br>            <span
 style="color: rgb(0, 0, 153);">org.jboss.seam.jsf.SeamPhaseListener</span><br>        <span
 class="xml-tag">&lt;/phase-listener</span><span class="xml-tag">&gt;</span><br><span
 class="xml-tag">&lt;/lifecycle</span><span class="xml-tag">&gt;</span><br><span
 class="xml-tag"></span><span class="xml-tag"><br></span></pre>
  </li>
  <li><span class="xml-tag">add the following&nbsp; context parameter
to your web.xml file</span>
    <pre><span class="xml-tag">&lt;<span style="color: rgb(204, 0, 0);">context-param</span></span><span
 class="xml-tag">&gt;</span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">param-name</span></span><span
 class="xml-tag">&gt;</span><br>          <span
 style="color: rgb(0, 0, 153);"> org.jboss.seam.core.init.jndiPattern</span><br>     <span
 class="xml-tag">&lt;/</span><span class="xml-tag">param-name</span><span
 class="xml-tag">&gt;</span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">param-value</span></span><span
 class="xml-tag">&gt;</span><br>           java:comp/env/<span
 style="font-style: italic; color: rgb(0, 102, 0);">your ear name</span>/#{ejbName}/local<br>     <span
 class="xml-tag">&lt;/param-value</span><span class="xml-tag"></span><span
 class="xml-tag">&gt;</span>    <span class="xml-tag"></span><br><span
 class="xml-tag">&lt;/context-param</span><span class="xml-tag">&gt;</span></pre>
  </li>
  <li><span class="xml-tag">add the following listener class to your
web.xml file<br>
    </span>
    <pre><span class="xml-tag">&lt;<span style="color: rgb(204, 0, 0);">listener</span></span><span
 class="xml-tag">&gt;</span><br>        <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">listener-class</span></span><span
 class="xml-tag">&gt;</span><br>            <span
 style="color: rgb(0, 0, 153);">org.jboss.seam.servlet.SeamListener</span><br>        <span
 class="xml-tag">&lt;/</span><span class="xml-tag">listener-class</span><span
 class="xml-tag">&gt;</span><br><span class="xml-tag">&lt;/</span><span
 class="xml-tag">listener</span><span class="xml-tag"></span><span
 class="xml-tag">&gt;</span></pre>
    <span class="xml-tag"></span></li>
  <li>For any session EJB's referenced from the web, add&nbsp; EJB
references to your web.xml, for example:<br>
    <pre><span class="xml-tag">&lt;<span style="color: rgb(204, 0, 0);">ejb-local-ref</span></span><span
 class="xml-tag">&gt;</span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">ejb-ref-name</span></span><span
 class="xml-tag"></span>&gt;<span
 style="font-style: italic; color: rgb(0, 102, 0);">your ear name</span>/CatalogBean/local<span
 class="xml-tag">&lt;/ejb-ref-name</span><span class="xml-tag"></span>&gt;<span
 class="xml-tag"></span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">ejb-ref-type</span></span><span
 class="xml-tag"></span>&gt;Session<span class="xml-tag">&lt;/ejb-ref-type</span>&gt;<span
 class="xml-tag"></span><span class="xml-tag"></span><span
 class="xml-tag"></span><span class="xml-tag"></span><span
 class="xml-tag"></span><span class="xml-tag"></span><span
 class="xml-tag"></span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">local-home</span>/</span><span
 class="xml-tag"></span>&gt;<span class="xml-tag"></span><span
 class="xml-tag"></span><span class="xml-tag"></span><span
 class="xml-tag"></span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">local</span></span>&gt;<span
 style="font-style: italic; color: rgb(0, 102, 0);">your package name</span>.Catalog<span
 class="xml-tag">&lt;/local</span><span class="xml-tag"></span>&gt;<span
 class="xml-tag"></span><br>     <span class="xml-tag">&lt;<span
 style="color: rgb(204, 0, 0);">ejb-link</span></span>&gt;CatalogBean<span
 class="xml-tag">&lt;/ejb-link</span>&gt;<span class="xml-tag"></span><span
 class="xml-tag"></span><br><span class="xml-tag">&lt;/</span><span
 class="xml-tag">ejb-local-ref</span><span class="xml-tag">&gt;</span></pre>
  </li>
  <li>For any EJB's referenced from the web add&nbsp; a Seam
interceptor to
the EJB, for example : <code><span
 style="font-weight: bold; color: rgb(204, 0, 0);">@Interceptors</span>({<span
 style="color: rgb(0, 0, 153);">org.jboss.seam.ejb.SeamInterceptor.class</span>})</code></li>
</ul>
<h2>References:</h2>
<ul>
  <li><a href="http://in.relation.to/Bloggers/WhatsNewInSeam2">What's
new in Seam 2.0</a><br>
  </li>
  <li><a
 href="http://weblogs.java.net/blog/bleonard/archive/2007/06/seam_refresh_1.html">Seam
Refresh</a>&nbsp; <span style="text-decoration: underline;"></span></li>
  <li><span style="text-decoration: underline;"></span><a
 href="http://docs.jboss.org/seam/2.0.0.GA/reference/en/html/en/html/tutorial.html">Seam
Tutorial</a></li>
  <li><a
 href="http://www.michaelyuan.com/blog/2007/02/28/glassfish-and-seam-tips/">Glassfish
and Seam Tips</a></li>
  <li><a
 href="http://www.amazon.com/exec/obidos/ASIN/0131347969/mobileenterpr-20/">JBoss
Seam: Simplicity and Power Beyond Java book</a><br>
  </li>
  <li><a
 href="https://blueprints.dev.java.net/bpcatalog/ee5/persistence/index.html">Java
BluePrints Solutions Catalog for the Java Persistence APIs</a>
contains a collection of topics and example applications.</li>
  <li><a href="https://glassfish.dev.java.net/javaee5/persistence/"
 target="bpcatalog">Java
Persistence reference page on GlassFish Project&nbsp;</a></li>
  <li><a href="http://java.sun.com/javaee/5/docs/tutorial/doc/">Java
EE tutorial,&nbsp; for good tutorial on JSF and JPA</a> </li>
  <li><a href="http://www.apress.com/book/bookDisplay.html?bID=10093">Pro
EJB 3: Java Persistence API book</a></li>
</ul>
<br>
<a href="http://weblogs.java.net/blog/caroljmcdonald/"
 target="bpcatalog"></a><br>
<br>

]]>

</content>
</entry>
<entry>
<title>Sample Application using JSF, Spring 2.5, and Java Persistence APIs</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/caroljmcdonald/archive/2008/01/sample_applicat_5.html" />
<modified>2008-02-12T04:32:03Z</modified>
<issued>2008-01-07T22:36:33Z</issued>
<id>tag:weblogs.java.net,2008:/blog/caroljmcdonald/61.8939</id>
<created>2008-01-07T22:36:33Z</created>
<summary type="text/plain">I updated my Sample Application using JSF, Spring, and JPA to use the Spring 2.5 framework which is available with Netbeans 6 and Glassfish v2.</summary>
<author>
<name>caroljmcdonald</name>

<email>carol.mcdonald@sun.com</email>
</author>
<dc:subject>Community: Java Enterprise</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/caroljmcdonald/">
<![CDATA[
<br>
<h3>Sample Application using JSF, Spring 2.5, and Java Persistence APIs
with Netbeans 6 and Glassfish v2<br>
</h3>
<br>
<br>
I took this example&nbsp;&nbsp;<a
 href="http://weblogs.java.net/blog/caroljmcdonald/archive/2007/06/sample_applicat.html">Sample
Application using JSF, Spring 2.0, and Java Persistence APIs</a>&nbsp;
and updated it to use the Spring 2.5 framework (which comes with
Netbeans 6) on Glassfish v2. <br>
You can dowload the&nbsp; <a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555&amp;expandFolder=7555&amp;folderID=0">sample
code&nbsp;</a>&nbsp; and a related presentation&nbsp; <a
 href="https://techdayscode.dev.java.net/servlets/ProjectDocumentList?folderID=7555&amp;expandFolder=7555&amp;folderID=0">JavaServer
Faces, Java Persistence API, Java EE, Spring, Seam.</a><span
 style="font-weight: bold;"><br>
<br>
</span><br>
<h3>Explanation of the usage of JSF, Spring 2.5 , and Java Persistence
APIs in a sample Store Catalog Application</h3>
The image below shows the Catalog Listing page, which allows a user to
page through a list of items
in a store. <br>
<br>
<div style="margin-left: 40px;">
<img alt="listpage.jpg"
 src="http://weblogs.java.net/blog/caroljmcdonald/archive/images/listpage.jpg"><br>
</div>
<br>
The List.jsp page uses a JSF <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">dataTable</code>
component to display a list of
catalog items<br>
<br>
The dataTable component is useful when you want to show a set of
results in a table. In a JavaServer Faces application, the <code
 style="color: rgb(204, 0, 0); font-weight: bold;" class="cCode">UIData</code>
component
(the superclass of dataTable)&nbsp; supports binding to a collection of
data objects. It does the
work of iterating over each record in the data source. The HTML <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">dataTable</code>
<span style="color: rgb(204, 0, 0); font-weight: bold;">renderer</span>
displays the data as an HTML table. <br>
<br>
In the List.jsp web page the dataTable is defined as shown below:&nbsp;
(Note: <span style="color: rgb(204, 0, 0); font-weight: bold;">Red</span>
colors
are for <span style="color: rgb(204, 0, 0); font-weight: bold;">Java EE</span>
tags, annotations code, <span
 style="color: rgb(0, 0, 153); font-weight: bold;">Blue</span> for <span
 style="color: rgb(0, 0, 153); font-weight: bold;">Spring</span>
specific
and <span style="color: rgb(0, 102, 0); font-weight: bold;">Green</span>
for <span style="color: rgb(0, 102, 0); font-weight: bold;">my code</span>
or <span style="color: rgb(0, 102, 0); font-weight: bold;">variables</span>)<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from:&nbsp; List.jsp<br>
      </b></td>
    </tr>
    <tr>
      <td> <code><br>
      </code><code>&lt;<span
 style="font-weight: bold; color: rgb(204, 0, 0);">h:dataTable</span><span
 style="color: rgb(204, 0, 0);"> </span><span
 style="font-weight: bold; color: rgb(204, 0, 0);">value</span>='<span
 style="font-weight: bold;">#{<span style="color: rgb(0, 102, 0);">itemController</span>.</span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">items</span><span
 style="font-weight: bold;">}</span>' <span
 style="font-weight: bold; color: rgb(204, 0, 0);">var</span>='<span
 style="color: rgb(0, 102, 0); font-weight: bold;">dataTableItem</span>'<br>
&nbsp;border="1"&nbsp; cellpadding="2" cellspacing="0"&gt;</code><code><br>
      <br>
      </code></td>
    </tr>
  </tbody>
</table>
<br>
The <code style="color: rgb(204, 0, 0); font-weight: bold;"
 class="cCode">value</code> attribute of a <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">dataTable</code>
tag references the data to be included
in the table. The <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">var</code>
attribute specifies a
name that is used by the components within the <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">dataTable</code>
tag as an alias to the data referenced in the <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">value</code>
attribute of <code style="font-weight: bold; color: rgb(204, 0, 0);"
 class="cCode">dataTable</code>.&nbsp; In the <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">dataTable</code>
tag from the <code class="cCode"><span
 style="color: rgb(0, 102, 0); font-weight: bold;">List</span>.jsp</code>
page, the <code style="font-weight: bold; color: rgb(204, 0, 0);"
 class="cCode">value</code> attribute points to a list
of catalog items. The <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">var</code>
attribute points
to a single item in that list. As the <code
 style="color: rgb(204, 0, 0); font-weight: bold;" class="cCode">UIData</code>
component iterates through the list, each reference to <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">dataTableItem</span></code><code
 class="cCode"></code> points to the current item in the
list.<br>
<br>
The dataTable's <code style="font-weight: bold; color: rgb(204, 0, 0);"
 class="cCode">value</code>
is bound to the <code><span style="font-weight: bold;"></span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">items</span></code>
property
of the <code><span style="font-weight: bold;"><span
 style="color: rgb(0, 102, 0);">itemController</span></span></code>
ManagedBean.<br>
This <code><span style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code><span
 style="font-weight: bold;"></span> ManagedBean<b> </b><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">items</span></code>
property is defined as shown below:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code><span
 style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code><span
 style="font-weight: bold;"></span><b>.java</b></td>
    </tr>
    <tr>
      <td>&nbsp; &nbsp; import <span style="color: rgb(0, 0, 153);">org.springframework.context.annotation.Scope;</span><br>
&nbsp;&nbsp;&nbsp; import <span style="color: rgb(0, 0, 153);">org.springframework.stereotype.Controller;&nbsp;</span><br>
&nbsp; <br>
      <code><span style="font-weight: bold; color: rgb(0, 0, 153);">&nbsp;
@Controller("</span></code><code><span style="font-weight: bold;"><span
 style="color: rgb(0, 102, 0);">itemController</span></span></code><code><span
 style="font-weight: bold; color: rgb(0, 0, 153);">")<br>
&nbsp; @Scope("session")</span><br>
&nbsp;
public class <span style="color: rgb(0, 102, 0); font-weight: bold;">ItemController</span>
{</code><br>
      <span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;
public <span style="color: rgb(204, 0, 0); font-weight: bold;">DataModel</span>
      <span style="color: rgb(0, 102, 0); font-weight: bold;">getItems</span>()
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (model==null&nbsp; ||
index != firstItem){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
model=getNextItems();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.model;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; public DataModel getNextItems()
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; model = new <span
 style="color: rgb(204, 0, 0); font-weight: bold;">ListDataModel</span>(<span
 style="color: rgb(0, 102, 0); font-weight: bold;">catalogService.getItems</span>(firstItem,batchSize));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index =
firstItem;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.model;<br>
&nbsp;&nbsp;&nbsp; }</span><code><br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
<br>
<code><span style="color: rgb(51, 51, 255); font-weight: bold;"><span
 style="color: rgb(0, 0, 153);">@Controller</span> </span></code>is a <span
 style="font-weight: bold; color: rgb(0, 0, 153);">Spring 2.5</span>
"stereotype" annotation, <strong>@Repository, </strong><strong>@Service</strong>
and <strong>@Controller </strong>are role designations for a common
three-tier architecture (data access objects, services, and web
controllers). <a href="http://www.infoq.com/articles/spring-2.5-part-1">By
clearly indicating application roles, these stereotypes facilitate the
use of Spring AOP and post-processors for providing additional behavior
to the annotated objects based on those roles.</a> The <code><span
 style="font-weight: bold; color: rgb(0, 0, 153);">@Scope("session")</span></code>
annotation binds a web-tier Spring-managed object to the specified
scope.&nbsp; The&nbsp; Spring&nbsp; 2.5 component scanning
functionality removes the need to define Web tier "controllers"&nbsp;
in the faces-config.xml.&nbsp; The following configuration is used to
trigger the
auto-detection of all web controllers:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr style="color: rgb(0, 0, 153); font-weight: bold;"
 class="bg-white">
      <td>Code Sample from: applicationContext.xml </td>
    </tr>
    <tr>
      <td>
      <pre style="color: rgb(0, 0, 153); font-weight: bold;"><br></pre>
&nbsp; <code><span style="color: rgb(0, 0, 153); font-weight: bold;">&lt;context:component-scan
base-package="<span style="color: rgb(0, 102, 0);">sessionpagination</span>"
/&gt;</span><br>
      <br>
      </code></td>
    </tr>
  </tbody>
</table>
&nbsp;<br>
<a
 href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/jsf/el/SpringBeanFacesELResolver.html"><br>
To integrate Spring with JSF</a> configure the Spring&nbsp;
JSF 1.2 <code>ELResolver</code> that delegates to the Spring root <code>WebApplicationContext</code>,
resolving name references to Spring-defined beans.&nbsp;<code><span
 style="color: rgb(0, 0, 153); font-weight: bold;"></span></code><span
 style="color: rgb(204, 0, 0); font-weight: bold;"><span
 style="color: rgb(0, 0, 0);"></span></span>Configure this resolver in
your <code>faces-config.xml</code> file as follows:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: faces-context.xml</b></td>
    </tr>
    <tr>
      <td> <br>
&nbsp; <code style="font-weight: bold;">&lt;<span
 style="color: rgb(204, 0, 0);">application</span>&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;<span style="color: rgb(204, 0, 0);">el-resolver</span>&gt;<br>
&nbsp; &nbsp; <span style="color: rgb(0, 0, 153);">org.springframework.web.jsf.el.SpringBeanFacesELResolver</span><br>
&nbsp;&nbsp;&nbsp; &lt;/el-resolver&gt;<br>
&nbsp;&lt;/application&gt;<br>
&nbsp; </code><code style="font-weight: bold;"></code><br>
      <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
<br>
The <code><span style="color: rgb(0, 102, 0); font-weight: bold;">ItemController</span></code>
<span style="font-family: monospace;"><span
 style="color: rgb(0, 102, 0); font-weight: bold;">getItems</span></span>()
method wraps a List of item objects, returned from the <span
 style="font-family: monospace;"><span
 style="color: rgb(0, 102, 0); font-weight: bold;">catalogService</span></span>,&nbsp;
in a <span style="font-family: monospace;"><span
 style="color: rgb(204, 0, 0); font-weight: bold;">DataModel</span></span>.
<br>
<code style="color: rgb(204, 0, 0); font-weight: bold;" class="cCode">UIData</code>,
the superclass of <code
 style="font-weight: bold; color: rgb(204, 0, 0);" class="cCode">dataTable</code>,
supports data binding to a
collection of data objects represented by a <span
 style="font-family: monospace;"><span
 style="color: rgb(204, 0, 0); font-weight: bold;">DataModel</span></span>
instance.&nbsp; The data
collection underlying a DataModel instance is modeled as a collection
of row objects that can be accessed by a row index.&nbsp; The APIs
provide mechanisms to position to a specified row index, and to
retrieve an object that represents the data that corresponds to the
current row index.&nbsp;&nbsp;&nbsp; <br>
<br>
The <code><span style="color: rgb(0, 102, 0); font-weight: bold;">Item</span></code>
properties Name, Photo, and <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">price</span></code>&nbsp;&nbsp;<code><span
 style="color: rgb(0, 102, 0); font-weight: bold;"></span></code>are
displayed with the <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">column</span></code>
component:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: List.jsp<br>
      </b></td>
    </tr>
    <tr>
      <td> <code><br>
&nbsp; &lt;<span style="color: rgb(204, 0, 0); font-weight: bold;">h:column</span>&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<span
 style="color: rgb(204, 0, 0); font-weight: bold;">f:facet</span> name="<span
 style="color: rgb(204, 0, 0); font-weight: bold;">header</span>"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<span
 style="color: rgb(204, 0, 0); font-weight: bold;">h:outputText</span> <span
 style="color: rgb(204, 0, 0); font-weight: bold;">value</span>="Price"/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/f:facet&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<span
 style="color: rgb(204, 0, 0); font-weight: bold;">h:outputTex</span>t <span
 style="color: rgb(204, 0, 0); font-weight: bold;">value</span>="#{<span
 style="color: rgb(0, 102, 0); font-weight: bold;">dataTableItem.price</span>}"/&gt;<br>
&nbsp;
&lt;/h:column&gt;<br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
The <code><span style="color: rgb(204, 0, 0); font-weight: bold;">column</span></code>
tags represent columns of data in a <code
 style="color: rgb(204, 0, 0); font-weight: bold;" class="cCode">UIData</code>
component. While
the UIData component is iterating over the rows of data, it processes
the UIColumn component associated with each column tag for each row in
the table.<br>
<br>
The <code style="color: rgb(204, 0, 0); font-weight: bold;"
 class="cCode">UIData</code> component&nbsp; iterates through the list
of items
(<code><span style="font-weight: bold;"><span
 style="color: rgb(0, 102, 0);">item</span>.</span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">items</span></code>)&nbsp;
and displays the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">dataTableItem.price</span></code>.
Each
time UIData iterates through the list of items, it renders one cell in
each <code><span style="color: rgb(204, 0, 0); font-weight: bold;">column</span></code>.<br>
<br>
The dataTable and column tags use <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">facet</span></code>
to represent parts of the
table that are not repeated or updated. These include <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">header</span></code>s,
footers,
and captions. <br>
<br>
The <code><span style="color: rgb(0, 102, 0); font-weight: bold;">catalogService</span></code>,
and its implementation&nbsp; <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogDAO</span></code><code>,</code>&nbsp;
is defined as a <span style="color: rgb(0, 0, 153); font-weight: bold;">Spring
bean</span> in the Spring configuration resource file <span
 style="color: rgb(0, 0, 153); font-weight: bold;"><span
 style="color: rgb(0, 0, 0);">/</span><span
 style="color: rgb(204, 0, 0);">WEB-INF</span><span
 style="color: rgb(0, 0, 0);">/</span>applicationContext</span>.xml<span
 style="font-style: italic;"> </span>:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><span
 style="color: rgb(0, 0, 153); font-weight: bold;">applicationContext</span><b>.xml
      </b></td>
    </tr>
    <tr>
      <td> <code> &nbsp;&nbsp; <br>
&nbsp;&nbsp;<span style="font-weight: bold;">&nbsp; &lt;</span><span
 style="color: rgb(0, 0, 153); font-weight: bold;">bean</span><span
 style="font-weight: bold;"> </span><span
 style="color: rgb(0, 0, 153); font-weight: bold;">id</span><span
 style="font-weight: bold;">="</span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">catalogService</span><span
 style="font-weight: bold;">" </span><span
 style="color: rgb(0, 0, 153); font-weight: bold;">class</span><span
 style="font-weight: bold;">="</span><span
 style="color: rgb(0, 102, 0); font-weight: bold;">service.CatalogDAO</span><span
 style="font-weight: bold;">"/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br
 style="font-weight: bold;">
&nbsp; <span style="font-weight: bold;"></span><span
 style="font-weight: bold;"></span><br style="font-weight: bold;">
      <span style="font-weight: bold;">&nbsp;&nbsp;&nbsp; </span><br
 style="font-weight: bold;">
      <span style="font-weight: bold;">&lt;/beans&gt;</span> </code><br>
      </td>
    </tr>
  </tbody>
</table>
<div style="margin-left: 40px;"><br>
</div>
&nbsp; <span style="color: rgb(204, 0, 0);"><span
 style="color: rgb(0, 0, 0);">The <span
 style="color: rgb(0, 0, 153); font-weight: bold;">Spring</span><span
 style="font-weight: bold;"> </span>root
WebApplicationContext</span></span> will inject the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">catalogService</span></code>
<span style="color: rgb(0, 0, 153); font-weight: bold;">Spring Bean</span>
into the <code><span style="color: rgb(0, 102, 0); font-weight: bold;">catalogService</span>
</code><span style="color: rgb(204, 0, 0); font-weight: bold;">property
</span>of the<code> <span
 style="color: rgb(0, 102, 0); font-weight: bold;">ItemController</span>
</code><span style="color: rgb(204, 0, 0); font-weight: bold;">JSF
ManagedBean <span style="color: rgb(0, 0, 0);"></span></span><code>: </code><br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><code><span
 style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code><span
 style="font-weight: bold;"></span><b>.java</b><b></b></td>
    </tr>
    <tr>
      <td>&nbsp;&nbsp;&nbsp; <code><span
 style="font-weight: bold; color: rgb(0, 0, 153);">@Controller("</span></code><code><span
 style="font-weight: bold;"><span style="color: rgb(0, 102, 0);">itemController</span></span></code><code><span
 style="font-weight: bold; color: rgb(0, 0, 153);">")<br>
&nbsp; @Scope("session")</span></code><code><span
 style="font-weight: bold; color: rgb(0, 0, 153);"></span><br>
&nbsp;
public class <span style="color: rgb(0, 102, 0); font-weight: bold;">ItemController</span>
{<br>
      <br>
&nbsp; private CatalogService catalogService ;<br>
&nbsp; <span style="font-weight: bold; color: rgb(0, 0, 153);">@Autowired</span><br>
&nbsp; public void <span
 style="color: rgb(0, 102, 0); font-weight: bold;">setCatalogService</span>(CatalogService
catalogService) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.catalogService =
catalogService;&nbsp;<br>
&nbsp; } </code> <br>
      </td>
    </tr>
  </tbody>
</table>
<a href="http://www.infoq.com/articles/spring-2.5-part-1"></a><br>
<br>
<code><span style="color: rgb(51, 51, 255); font-weight: bold;"><span
 style="color: rgb(0, 0, 153);">@Autowired</span> </span></code><code><span
 style="color: rgb(51, 51, 255); font-weight: bold;"></span></code>is a
<span style="font-weight: bold; color: rgb(0, 0, 153);">Spring 2.5</span>
annotation<strong></strong> that makes it possible to<a
 href="http://www.infoq.com/articles/spring-2.5-part-1"> inject
dependencies that match by type.</a> This behavior is enabled for
fields,
constructors, and methods. To enable this, add this to the
applicationContext.xml:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: </b><span
 style="color: rgb(0, 0, 153); font-weight: bold;">applicationContext</span><b>.xml
      </b></td>
    </tr>
    <tr>
      <td>
      <pre style="color: rgb(0, 0, 0); font-weight: bold;"><br> &lt;context:annotation-config/&gt;</pre>
      <code><span style="font-weight: bold;"></span><span
 style="font-weight: bold;"></span><span style="font-weight: bold;"></span><br>
      </code></td>
    </tr>
  </tbody>
</table>
<div style="margin-left: 40px;"><br>
</div>
<br>
<br>
For more information on using JSF with Spring, see <a
 href="http://static.springframework.org/spring/docs/1.2.x/reference/webintegration.html">Spring
- Java/J2EE Application Framework Integrating with JavaServer Faces</a>
.<br>
<br>
<h4>Using the Java Persistence API (JPA) with Spring 2.5</h4>
The Spring bean <code style="color: rgb(0, 102, 0); font-weight: bold;">CatalogDAO</code>
uses the Java
Persistence API
<span style="color: rgb(204, 0, 0); font-weight: bold;">EntityManager
Query </span>object to return a list of items.
The <code>CatalogDAO</code> annotates the field <code><span
 style="font-weight: bold;">private <span
 style="color: rgb(204, 0, 0);">EntityManager</span> em</span>;</code>&nbsp;
with <code style="color: rgb(204, 0, 0);"><span
 style="font-weight: bold;">@PersistenceContext</span></code>
<strong><em></em></strong>, which causes an entity manager to be
injected. <code>(</code>note that using the <code></code><code
 style="color: rgb(204, 0, 0);"><span style="font-weight: bold;">
@PersistenceContext</span></code><code><span
 style="color: rgb(153, 0, 0);"> </span></code>annotation is the same
way an
Entity Manager is injected for a <span style="color: rgb(204, 0, 0);">EJB
3.0 Session Bean</span><code></code>.)<br>
&nbsp;<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: CatalogDAO.java</b></td>
    </tr>
    <tr>
      <td> <code> <br>
      <span style="color: rgb(0, 0, 153); font-weight: bold;">@Repository</span><br
 style="color: rgb(0, 0, 153); font-weight: bold;">
      <span style="color: rgb(0, 0, 153); font-weight: bold;">@Transactional</span><br>
public class <span style="color: rgb(0, 102, 0); font-weight: bold;">CatalogDAO</span>
implements <span style="color: rgb(0, 102, 0); font-weight: bold;">CatalogService</span>
{<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; <span
 style="font-weight: bold; color: rgb(204, 0, 0);">@PersistenceContext</span>(unitName="PetCatalogPu")<br>
&nbsp;&nbsp;&nbsp; private <span
 style="color: rgb(204, 0, 0); font-weight: bold;">EntityManager</span>
      <span style="font-weight: bold;">em</span>;<br>
      <br style="color: rgb(0, 0, 102); font-weight: bold;">
      <span style="color: rgb(0, 0, 102); font-weight: bold;">&nbsp;&nbsp;&nbsp;
      <span style="color: rgb(0, 0, 153);">@Transactional(readOnly =
true)</span></span><br>
&nbsp;&nbsp;&nbsp; public List&lt;Item&gt;&nbsp; <span
 style="color: rgb(0, 102, 0); font-weight: bold;">getItems</span>(int
firstItem,int batchSize) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">Query</span> q = <span
 style="font-weight: bold;">em.<span style="color: rgb(204, 0, 0);">createQuery</span></span>("select
object(o)
from Item as o");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q.<span
 style="color: rgb(204, 0, 0); font-weight: bold;">setMaxResults</span>(batchSize);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q.<span
 style="color: rgb(204, 0, 0); font-weight: bold;">setFirstResult</span>(firstItem);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Item&gt; items=
q.<span style="color: rgb(204, 0, 0); font-weight: bold;">getResultList</span>();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
items;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
<h4 style="font-weight: normal;">The Java Persistence <a
 href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Query.html">Query
APIs</a> are used to create and execute queries that can return a
list of results.&nbsp; The JPA Query interface provides
support for pagination via the setFirstResult() and setMaxResults()
methods: <code>q.<span
 style="color: rgb(204, 0, 0); font-weight: bold;">setMaxResults</span></code><b></b>(int&nbsp;maxResult)
sets the maximum number of results to retrieve.<b><span
 style="font-family: mon;"> </span></b><code>q.<span
 style="color: rgb(204, 0, 0); font-weight: bold;">setFirstResult</span></code>(int&nbsp;startPosition)
sets the position of the first result to retrieve.</h4>
In the code below, we show the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Item</span></code>
entity class which maps to the&nbsp; ITEM table that stores the
item instances. This is a
typical Java Persistence entity object. There are two requirements for
an entity:<br>
<ol>
  <li>annotating the class with an <span
 style="color: rgb(204, 0, 0); font-weight: bold;">@Entity</span>
annotation. <br>
  </li>
  <li> annotating&nbsp;&nbsp; the primary key identifier with <span
 style="color: rgb(204, 0, 0); font-weight: bold;">@Id </span><br>
  </li>
</ol>
Because the fields name, description.... are basic mappings from the
object fields to columns of the same name in the database table, they
don't have to be annotated.&nbsp; The O/R&nbsp; relationships with <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Address</span></code>
and <code><span style="color: rgb(0, 102, 0); font-weight: bold;">Product</span></code>
are also annotated. For more information on
defining JPA entities see <a
 href="http://www.apress.com/book/bookDisplay.html?bID=10093">Pro
EJB 3: Java Persistence API book</a>.<br>
<br>
<a name="code-example-2" target="bpcatalog"></a>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: Item.java</b></td>
    </tr>
    <tr>
      <td> <code><br>
      <span style="color: rgb(204, 0, 0); font-weight: bold;">@Entity</span><br>
public class <span style="color: rgb(0, 102, 0); font-weight: bold;">Item</span>
implements java.io.Serializable {<br>
      <br>
&nbsp; &nbsp; </code><code
 style="color: rgb(204, 0, 0); font-weight: bold;">@Id</code><code><span
 style="color: rgb(204, 0, 0); font-weight: bold;"> </span>&nbsp; <br>
&nbsp;&nbsp;&nbsp; private String itemID;</code><code></code><code><br>
&nbsp;&nbsp;&nbsp; private String name;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private String description;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private String imageurl;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private String imagethumburl;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private BigDecimal price;<br>
&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">@OneToOne</span><span
 style="color: rgb(204, 0, 0);">(cascade={CascadeType.PERSIST})</span><br>
&nbsp;&nbsp;&nbsp; private <span
 style="color: rgb(0, 102, 0); font-weight: bold;">Address</span>
address;<br>
      </code><code>&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">@ManyToOne</span><br>
&nbsp;&nbsp;&nbsp; private <span
 style="color: rgb(0, 102, 0); font-weight: bold;">Product</span>
product;</code><br>
      <code>&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; public Item() { }<br>
&nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; public String getItemID() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return itemID;<br>
&nbsp;&nbsp;&nbsp; }</code><code><br>
&nbsp;&nbsp;&nbsp; public void setItemID(String itemID) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.itemID = itemID;<br>
&nbsp;&nbsp;&nbsp;
}</code><br>
      <code>&nbsp;&nbsp;&nbsp; public String getName() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return name;<br>
&nbsp;&nbsp;&nbsp; }</code><code><br>
&nbsp;&nbsp;&nbsp; public void setName(String name) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.name = name;<br>
&nbsp;&nbsp;&nbsp; }</code><code>&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; public String getDescription() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return description;<br>
&nbsp;&nbsp;&nbsp; }</code><code><br>
&nbsp;&nbsp;&nbsp; public void setDescription(String
description) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.description = description;<br>
&nbsp;&nbsp;&nbsp; }</code><br>
      <code>&nbsp;&nbsp;&nbsp; public BigDecimal getPrice() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
price;<br>
&nbsp;&nbsp;&nbsp; }&nbsp; </code><code></code><code><br>
&nbsp;&nbsp;&nbsp; public void setPrice(BigDecimal price) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.price = price;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; public void setAddress(Address address) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.address = address;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; public Product getProduct() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return product;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; public void setProduct(Product product) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.product = product;<br>
&nbsp;&nbsp;&nbsp; }<br>
      <br>
&nbsp; &nbsp; ... <br>
}&nbsp;&nbsp;&nbsp; <br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
<br>
<br>
The <code><span style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code>
ManagedBean pages through the list of <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">Item</span></code>s
by
maintaining the firstItem and batchSize attributes and passing these as
parameters to the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogService&nbsp;</span></code><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">getItems</span></code>(firstItem,
batchSize) method.
The <code><span style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code>'s
<code>&lt;<span style="color: rgb(204, 0, 0); font-weight: bold;">managed-bean-scope</span>&gt;<span
 style="color: rgb(204, 0, 0); font-weight: bold;"></span></code> is
defined as <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">session</span></code>,
a JSF Managedbean
with session scope will be stored in the session meaning that the
bean's properties will stay alive for the life of the Http Session.<br>
<br>
<br>
The <code><span style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code>
<code><span style="color: rgb(0, 102, 0); font-weight: bold;">ItemCount&nbsp;</span></code>
property is&nbsp; used to get and display
the number of Catolog <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">item</span></code>s
in the&nbsp; data base on the <span
 style="color: rgb(0, 102, 0); font-weight: bold;">List</span>.jsp page:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: <span style="color: rgb(0, 102, 0);">List</span>.jsp</b></td>
    </tr>
    <tr>
      <td> <code><br>
&lt;<span style="color: rgb(204, 0, 0); font-weight: bold;">h:outputText</span>
      <span style="color: rgb(153, 0, 0); font-weight: bold;">value</span>="Item
#{<span style="color: rgb(0, 0, 0);"></span></code><code><span
 style="font-weight: bold;"><span style="color: rgb(0, 102, 0);">itemController</span></span></code><code><span
 style="color: rgb(0, 0, 0);"></span>.firstItem +1} ..#{</code><code><span
 style="font-weight: bold;"><span style="color: rgb(0, 102, 0);">itemController</span></span></code><code>.lastItem}
of #{<span style="color: rgb(0, 102, 0); font-weight: bold;"></span></code><code><span
 style="font-weight: bold;"><span style="color: rgb(0, 102, 0);">itemController</span></span></code><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">.itemCount</span>}"/&gt;<br>
      <br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
This <code><span style="font-weight: bold; color: rgb(0, 102, 0);">ItemController
</span></code><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">ItemCount </span></code>property
is defined as shown below:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: ItemController.java</b></td>
    </tr>
    <tr>
      <td> <code><br>
&nbsp;&nbsp;&nbsp; public int <span
 style="color: rgb(0, 102, 0); font-weight: bold;">getItemCount</span>()
{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int count = <span
 style="color: rgb(0, 102, 0); font-weight: bold;">catalogService.getItemsCount</span>();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
count;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; }<br>
      </code> </td>
    </tr>
  </tbody>
</table>
<br>
The <code><span style="font-weight: bold; color: rgb(0, 102, 0);">ItemController</span></code>
<code><span style="color: rgb(0, 102, 0); font-weight: bold;">getItemCount</span></code>()
method calls the <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogService</span></code>
interface to get
the count of the list of items. The <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogDAO</span></code>
Spring bean&nbsp; <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">getItemCount</span></code>()
method uses the JPA Query interface to get the count of
all items in the database item table:<br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from:&nbsp;</b><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogDAO</span></code><b>.java</b></td>
    </tr>
    <tr>
      <td> <code><span
 style="color: rgb(0, 0, 153); font-weight: bold;">@Repository</span><br
 style="color: rgb(0, 0, 153); font-weight: bold;">
      <span style="color: rgb(0, 0, 153); font-weight: bold;">@Transactional</span></code><br>
      <code>public class <span
 style="color: rgb(0, 102, 0); font-weight: bold;">CatalogDAO</span>
implements <span style="color: rgb(0, 102, 0); font-weight: bold;">CatalogService</span>
{<br>
      </code><code><span
 style="font-weight: bold; color: rgb(204, 0, 0);">&nbsp;
@PersistenceContext</span>(unitName="PetCatalogPu")<br>
&nbsp;
private <span style="color: rgb(204, 0, 0); font-weight: bold;">EntityManager</span>
      <span style="font-weight: bold;">em</span>;</code><br>
      <code>. . .<br>
      </code><code>&nbsp; </code><code><span
 style="color: rgb(0, 0, 102); font-weight: bold;"><span
 style="color: rgb(0, 0, 153);">@Transactional(readOnly = true)</span></span></code><br>
      <code>&nbsp; public int&nbsp;</code> <code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">getItemCount</span></code><code>()
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
 style="color: rgb(204, 0, 0); font-weight: bold;">Query</span> q =
entityManager.<span style="color: rgb(204, 0, 0); font-weight: bold;">createQuery</span>(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"select
count(o) from Item as
o");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int count =
((Long)q.<span style="color: rgb(204, 0, 0); font-weight: bold;">getSingleResult()).intValue();</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return count;<br>
&nbsp; }&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp; <br>
      </code> <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
A JSF <code><span style="color: rgb(204, 0, 0); font-weight: bold;">commandLink</span></code>
is&nbsp; used to provide a link to click on to
display the next page of items. The <code><span
 style="color: rgb(204, 0, 0); font-weight: bold;">commandLink</span></code>
tag represents an HTML hyperlink and is rendered as an HTML <code
 class="cCode">&lt;a&gt;</code> element. The <code class="cCode">commandLink</code>
tag is used to submit an <span
 style="color: rgb(204, 0, 0); font-weight: bold;">action event</span>
to the application.&nbsp; <br>
<br>
<table class="examplecode" border="1" cellpadding="2" cellspacing="0">
  <tbody>
    <tr class="bg-white">
      <td><b>Code Sample from: List.jsp</b></td>
    </tr>
    <tr>
      <td> <code><br style="color: rgb(204, 0, 0); font-weight: bold;">
      <span style="color: rgb(204, 0, 0); font-weight: bold;">&nbsp;&lt;h:commandLink</span>
      <span style="color: rgb(204, 0, 0); font-weight: bold;">action</span>="#{<span
 style="color: rgb(0, 102, 0); font-weight: bold;"></span></code><code><span
 style="font-weight: bold;"><span style="color: rgb(0, 102, 0);">itemController</span></span></code><code><span
 style="color: rgb(0, 102, 0); font-weight: bold;">.next</span>}"
value="Next
#{</code><code style="color: rgb(0, 0, 0);">itemController</code><code>.batchSize}"<br>
&nbsp;&nbsp;&nbsp;
rendered="#{itemController.lastItem + itemController.batchSize &lt;=
itemController.itemCount}"/&gt;&nbsp;<br>
      </code> <br>
      </td>
  