# 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

Run the example as follows:

>     mvn clean package glassfish:run

This deploys the web service using GlassFish V3 application server.

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.sun.com/japod/entry/jmaki_widgets_talking_to_jersey