jMaki Back-End Example

This example demonstrates providing jMaki widget JSON data models as Jersey resources.

The jMakiBackend application maintains a list of printers. The list can be manipulated by an end user via a RESTful API.

Two resources are also available, which provides jMaki table and tree widgets data models for the current data (printer list)

Contents

The example consists of the following:

com.sun.jersey.samples.jmaki.resources.PrintersResource
This class is the core of the appliaction. It holds the data model (printer list) and provides a RESTful interface for it.
com.sun.jersey.samples.jmaki.beans.*
This package contains JAXB beans, which are used for Java to JSON transformation. Besides the transformation, a Printer bean is also a data model for a printer list row. The bean is encapsulated in jMaki widget beans (PrinterTableModel and TreeModel).
com.sun.jersey.samples.jmaki.config.JAXBContextResolver
Provides a configuration point for Java to JSON transformation.

The mapping of the URI path space is presented in the following table:

URI path Resource HTTP methods
/printers bootstrap resource GET
/printers/list a list of printers GET
/printers/ids/{printerId} a printer row GET, PUT, DELETE
/printers/jMakiTree jMaki Tree data model GET
/printers/jMakiTable jMaki Table data model GET

Running the Example

If you are working with Jersey GlassFish update center module installed into your existing GlassFish instance, you will need to follow instructions at the module README file in order to deploy the example.

Otherwise, you can run the example using embedded GlassFish as follows:

mvn clean package embedded-glassfish:run

or you can run the example using Jetty as follows:

mvn clean package jetty:run

A WADL description may be accessed at the URL:

http://localhost:8080/jMakiBackend/webresources/application.wadl

You can also see an initial sample list of printers at the URL:

http://localhost:8080/jMakiBackend/webresources/printers/list

jMaki Front-End

To use the provided jMaki data models, you will need Netbeans 6.0 with jMaki plugin installed. Then simply create a new WebApplication and select jMaki AJAX Framework for it. You can than drag and drop appropriate widget (e.g.YahooTable) from the jMaki widgets panel to your index.jsp page. Then update the widget code to look like follows:

<a:widget name="yahoo.dataTable"
             service="http://localhost:8080/jMakiBackend/webresources/printers/jMakiTable"/>
Then you should be able to run your web application and see the table on your index page. A screenshot and further info is available at http://blogs.oracle.com/japod/entry/jmaki_widgets_talking_to_jersey