Dec 20

To include a calculated field in a ListGrid you need to create a new ListGridField and specify the cellFormatter property to handle calculating the fields value.

// Following example shows a data source that return two fields
// firstName and lastName
// A CellFormatter is used to concatenate the first and last name
// in a single field in the ListGrid


DataSource peopleDS = new RestDataSource();
peopleDS.addField(new DataSourceTextField("firstName"));
peopleDS.addField(new DataSourceTextField("lastName"));

final ListGrid people = new ListGrid();
people.setDataSource(peopleDS);

// Create a new "Name" field in ListGrid

ListGridField name = new ListGridField("name", "Name");

// Specify a CellFormatter to calculate the fields value

name.setCellFormatter(new CellFormatter()
{
   public String format(Object value, ListGridRecord record,
      int row, int column)
   {
        // Get 'firstName' and 'lastName' values 
        // from record being displayed

        String firstName = record.getAttributeAsString("firstName");
        String lastName = record.getAttributeAsString("lastName");

        // return concatenated name

        return firstName + " " + lastName;
   }
});

// Add calculated field to the ListGrid

people.setFields(name);

written by objects \\ tags: , , ,

Dec 19

By default the RestDataSource only supports static url’s. If your backend requires dynamic url’s then you need to subclass RestDataSource and override transformRequest(). In transformRequest() you can set the actionURL property as required by your backend server.


// Following example shows how to append 
// the entities if to the static update url

final RestDataSource restDataSource = new RestDataSource()
{
   @Override
   public Object transformRequest(DSRequest dsRequest)
   {
       if (dsRequest.getOperationType().equals(DSOperationType.UPDATE))
       {
          int id = JSOHelper.getAttributeAsInt(
              dsRequest.getData(), "id"));
          dsRequest.setActionURL(
             getUpdateDataURL()+"/"+id;
       }
       return super.transformRequest(dsRequest);
   }
};

written by objects \\ tags: , , ,

Dec 08

The method GWT.isScript() can be used to detect if a GWT application is running in Hosted Mode. It will return false when running in Hosted Mode.


if (!GWT.isScript())
{
   // Am running in Hosted Mode
}

written by objects \\ tags: