Step 6: Customize your GWT application

 

Now we will add a ListGrid component to your application which will be used to dispaly tabular data (just like dataTable does for JSF). Let's modify EntryPoint.java :

 


package com.sample.client;

import com.google.gwt.user.client.ui.RootPanel;
import com.sample.client.ds.ItemDS;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.ListGrid;

public class EntryPoint implements com.google.gwt.core.client.EntryPoint {

 public Canvas getViewPanel() {
 Canvas canvas = new Canvas();
 
 final ListGrid itemGrid = new ListGrid();          
 itemGrid.setWidth(500);  
 itemGrid.setHeight(224);  
 itemGrid.setShowAllRecords(true);  
 itemGrid.setDataSource(ItemDS.getInstance());  
 itemGrid.setAutoFetchData(true);  
 itemGrid.setCanEdit(true);  
 
 canvas.addChild(itemGrid);
 

 return canvas;
 }
 public void onModuleLoad() {
 RootPanel.get().add(getViewPanel());
 

 }
 

}

A ListGrid uses a DataSource object to map the fields contained in the grid. The binding can be done either with static data or with dynamic data. Let's see first an example with a static xml file.
package com.sample.client.ds;

 
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.types.FieldType;

public class ItemDS extends DataSource {  
 
 
 private static ItemDS instance = null;  
 
 public static ItemDS getInstance() {  
 if (instance == null) {  
 instance = new ItemDS("ItemDS");  
 }  
 return instance;  
 }  

 public ItemDS(String id) {  
 setID(id);  
 setRecordXPath("/collection/item");  
 
 DataSourceField nameField = new DataSourceField("name", FieldType.TEXT, "name");  
 DataSourceField priceField = new DataSourceField("price", FieldType.INTEGER, "price");  
 DataSourceField quantityField = new DataSourceField("quantity", FieldType.INTEGER, "quantity");  
 DataSourceField idField = new DataSourceField("id", FieldType.TEXT, "id");  

 setFields(nameField, priceField,quantityField,idField);  
 setDataURL("/items.xml");  
 
 }  

} 


The binding is done with the setDataURL method which binds data to the file items.xml.

Add the file items.xml will be added in the war folder of your prohect, so that it will be visible by your home page. Here's a short piece of it:

<collection>

<item>
<name>computer</name>
<price>2500</price>
<quantity>45</quantity>
<id>a1</id>
</item>

. . . . . .
</collection>

Ok, now you're ready to test your initial project. Compile (1) at first the project, so that client stubs will be created and then launch it (2) in hosted mode. This will launch an internal Web server which can be used to test your application before deploying it to the AS.


gwt google web toolkit jboss tutorial

 

If everything works correctly you should see displayed a ListGrid with the data from the XML.
gwt google web toolkit jboss tutorial
 

 

0
0
0
s2smodern