| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
<html><head><title>jMaki Back-End Example</title></head> |
| 44 |
|
| 45 |
|
| 46 |
<body> |
| 47 |
<h1>jMaki Back-End Example</h1> |
| 48 |
<p>This example demonstrates providing <a href="http://ajax.java.net">jMaki</a> |
| 49 |
widget JSON data models as Jersey resources. |
| 50 |
</p> |
| 51 |
<p>The jMakiBackend application maintains a list of printers. |
| 52 |
The list can be manipulated by an end user via a RESTful API.</p> |
| 53 |
<p>Two resources are also available, which provides jMaki table and tree widgets |
| 54 |
data models for the current data (printer list)</p> |
| 55 |
|
| 56 |
<h2>Contents</h2> |
| 57 |
<p>The example consists of the following: |
| 58 |
</p><dl> |
| 59 |
<dt><code>com.sun.jersey.samples.jmaki.resources.PrintersResource</code></dt> |
| 60 |
<dd>This class is the core of the appliaction. It holds the data model (printer list) |
| 61 |
and provides a RESTful interface for it. |
| 62 |
</dd> |
| 63 |
<dt><code>com.sun.jersey.samples.jmaki.beans.*</code></dt> |
| 64 |
<dd>This package contains JAXB beans, which are used for Java to JSON |
| 65 |
transformation. Besides the transformation, a <code>Printer</code> bean |
| 66 |
is also a data model for a printer list row. The bean is encapsulated |
| 67 |
in jMaki widget beans (<code>PrinterTableModel</code> and <code>TreeModel</code>). |
| 68 |
</dd> |
| 69 |
<dt><code>com.sun.jersey.samples.jmaki.config.JAXBContextResolver</code></dt> |
| 70 |
<dd>Provides a configuration point for Java to JSON transformation. |
| 71 |
</dd> |
| 72 |
</dl> |
| 73 |
<p>The mapping of the URI path space is presented in the following table:</p> |
| 74 |
<table border="1"> |
| 75 |
<tr> |
| 76 |
<th>URI path</th> |
| 77 |
<th>Resource</th> |
| 78 |
<th>HTTP methods</th> |
| 79 |
</tr> |
| 80 |
<tr> |
| 81 |
<td>/printers</td> |
| 82 |
<td>bootstrap resource</td> |
| 83 |
<td>GET</td> |
| 84 |
</tr> |
| 85 |
<tr> |
| 86 |
<td>/printers/list</td> |
| 87 |
<td>a list of printers</td> |
| 88 |
<td>GET</td> |
| 89 |
</tr> |
| 90 |
<tr> |
| 91 |
<td>/printers/ids/{printerId}</td> |
| 92 |
<td>a printer row</td> |
| 93 |
<td>GET, PUT, DELETE</td> |
| 94 |
</tr> |
| 95 |
<tr> |
| 96 |
<td>/printers/jMakiTree</td> |
| 97 |
<td>jMaki Tree data model</td> |
| 98 |
<td>GET</td> |
| 99 |
</tr> |
| 100 |
<tr> |
| 101 |
<td>/printers/jMakiTable</td> |
| 102 |
<td>jMaki Table data model</td> |
| 103 |
<td>GET</td> |
| 104 |
</tr> |
| 105 |
</table> |
| 106 |
|
| 107 |
<h2>Running the Example</h2> |
| 108 |
<p>If you are working with Jersey GlassFish update center module installed into your existing GlassFish instance, |
| 109 |
you will need to follow instructions at <a href="../../README.html">the module README file</a> in order to deploy the example. |
| 110 |
<p>Otherwise, you can run the example using embedded GlassFish as follows:</p> |
| 111 |
<blockquote><code>mvn clean package embedded-glassfish:run</code></blockquote> |
| 112 |
<p>or you can run the example using Jetty as follows:</p> |
| 113 |
<blockquote><code>mvn clean package jetty:run</code></blockquote> |
| 114 |
<p>A <a href="http://wadl.java.net/#spec">WADL description</a> may be accessed at the URL:</p> |
| 115 |
<blockquote><code><a href="http://localhost:8080/jMakiBackend/webresources/application.wadl">http://localhost:8080/jMakiBackend/webresources/application.wadl</a></code></blockquote> |
| 116 |
|
| 117 |
<p>You can also see an initial sample list of printers at the URL:</p> |
| 118 |
<blockquote><code><a href="http://localhost:8080/jMakiBackend/webresources/printers/list">http://localhost:8080/jMakiBackend/webresources/printers/list</a></code></blockquote> |
| 119 |
<h2>jMaki Front-End</h2> |
| 120 |
<p>To use the provided jMaki data models, you will need Netbeans 6.0 with jMaki plugin installed. |
| 121 |
Then simply create a new WebApplication and select jMaki AJAX Framework for it. |
| 122 |
You can than drag and drop appropriate widget (e.g.YahooTable) |
| 123 |
from the jMaki widgets panel to your <code>index.jsp</code> page. |
| 124 |
Then update the widget code to look like follows: |
| 125 |
<pre> |
| 126 |
<a:widget name="yahoo.dataTable" |
| 127 |
service="http://localhost:8080/jMakiBackend/webresources/printers/jMakiTable"/> |
| 128 |
</pre> |
| 129 |
Then you should be able to run your web application and see the table on your index page. |
| 130 |
A screenshot and further info is available at <a href="http://blogs.oracle.com/japod/entry/jmaki_widgets_talking_to_jersey">http://blogs.oracle.com/japod/entry/jmaki_widgets_talking_to_jersey</a> |
| 131 |
</body></html> |