The AS7 book!

JBoss Tuning

Top Programming Sites
Home Web Dojo Toolkit Tutorial

Dojo Toolkit Tutorial

dojo toolkit tutorialToday there's a vast choice of Javascript libraries which can be used to create effective layouts in a matter of few lines of code. Dojo Toolkit is an open source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross-platform, JavaScript/Ajax-based applications and web sites. In this tutorial we will show how to provide a simple Dojo Toolkit GUI to your RESTeasy Web services.

 

 

Dojo Toolkit bears some similarities with JQuery, however it is designed to go beyond JQuery to add full browser-side data objects in addition to a huge variety of other goodness. Some of the strong points of Dojo include:

 

 

Introduces the concept of classes, constructors, and inheritance in JavaScript, allowing you to build object-oriented JavaScript code.

 

Allows you to build more-manageable code by breaking your code into modules.


Simplifies Ajax programming by providing infrastructure code for making asynchronous requests using XMLHttpRequest and cross-browser-compatible DOM-manipulation code.

 

Attention to details in widgets: (support for i18n, support for l10n, provisions for people with special needs and so on).

 

You can download Dojo Javascript library at http://dojotoolkit.org/

Or, you can use it on the cloud by including this line in your web page:

<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"></script>


We cannot describe all the characteristics of Dojo in a single article, however we will show how to use it with a JBoss server application delivering RESTful Web services.

(The following code has been test on JBoss AS 6, however it will work as well on JBoss AS 7).

Here's a basic RESTful web service which produces an array of Items. Check out this article for information on how to deploy RESTeasy Web services on JBoss AS.


 @GET
 @Path("items")
 @Produces("application/json")
 @Mapped
 public ItemList  getJSONItems() {
 ArrayList list = new ArrayList();
 Item item1 = new Item("X1234","computer",2500);
 Item item2 = new Item("M1234","Monitor",500);
 Item item3 = new Item("AB123","chair",100);
 Item item4 = new Item("T001","table",200);

 list.add(item1);
 list.add(item2);
 list.add(item3);
 list.add(item4);

 return new ItemList(list);
 }  
    
And the corresponding Wrapper class:
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;

@XmlRootElement(name="listing")
public class ItemList
{
 private List<Item> items;

 public ItemList() { }

 public ItemList(List<Item> items)
 {
 this.items = items;
 }

 @XmlElement(name="items")
 public List<Item> getItems()
 {
 return items;
 }
}   

And finally the Item class:
import java.io.Serializable;

import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement 
public class Item implements Serializable
{
 private String id;
 private String name;
 private int price;
 
 public String getName()
 {
 return name;
 }
 public void setName(String name)
 {
 this.name = name;
 }
 public String getId()
 {
 return id;
 }
 public void setId(String id)
 {
 this.id = id;
 }
 public int getPrice()
 {
 return price;
 }
 public void setPrice(int price)
 {
 this.price = price;
 }
 
 public Item(String id, String name, int price)
 {
 this.id = id;
 this.name = name;
 this.price = price;
 }

}


 



 

License

Mastertheboss.com Unless stated, all the contents of this site is licensed under Creative Comons License
Licenza Creative Commons