开发者

Ext-GWT (GXT) simple REST attempt not working

I'm trying to get a simple GXT application to retrieve data from an external server using REST.

I have found the following example online, and for the life of me, I cannot understand why my table isn't getting populated. It also appears as if the data isn't retrieved. I would appreciate any help! Thank you.

/*
 * Ext GWT 2.2.3 - Ext for GWT
 * Copyright(c) 2007-2010, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
package com.extjs.gxt.samples.mail.client.widget;


import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.HttpProxy;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.XmlReader;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.http.client.RequestBuilder;


public class ContactPanel extends ContentPanel {

  @SuppressWarnings("rawtypes")
pub开发者_运维问答lic ContactPanel() {


        setHeading("Contacts");     
        setStyleAttribute("margin", "5px");
        setHeaderVisible(true);
        setBodyBorder(true);

        setAutoHeight(true);
        setLayout(new RowLayout(Orientation.VERTICAL));


        List<ColumnConfig> configs = new ArrayList<ColumnConfig>();   
        configs.add(new ColumnConfig("departureCity", "From", 120));  
        configs.add(new ColumnConfig("arrivalCity", "To", 120));  

        ColumnConfig config = new ColumnConfig("departureTime", "departureTime", 150);  
        config.setAlignment(HorizontalAlignment.LEFT);
        configs.add(config);

        configs.add(new ColumnConfig("arrivalTime", "Arrivaltime", 150));  
        configs.add(new ColumnConfig("flightNo", "Flightnr", 70));  
        config = new ColumnConfig("price", "Price", 120);
        config.setAlignment(HorizontalAlignment.LEFT);
        configs.add(config);  

        ColumnModel cm = new ColumnModel(configs);



        ModelType type = new ModelType();  
        type.setRoot("flightList");
        type.setRecordName("flight");   

        type.addField("departureCity");  
        type.addField("arrivalCity");  
        type.addField("departureTime");  
        type.addField("arrivalTime");  
        type.addField("flightNo");  
        type.addField("price");  

        // use a http proxy to get the data  
        RequestBuilder builder = new RequestBuilder(
                RequestBuilder.GET,
                //"/flights.xml");
                "http://tutorialsjava.com/demo/flights.xml");
        HttpProxy proxy = new HttpProxy(builder);  

        // need a loader, proxy, and reader  
        XmlReader reader = new XmlReader(type);  

        final BaseListLoader loader = new BaseListLoader(proxy, reader);  

        ListStore<ModelData> store = new ListStore<ModelData>(loader);  
        final Grid grid = new Grid<ModelData>(store, cm);  

        grid.setStyleAttribute("borderTop", "none");    
        grid.setBorders(true);   
        grid.setStripeRows(true);   
        grid.setAutoWidth(true);
        grid.setHeight(160);
        grid.getView().setForceFit(true);

        loader.setRemoteSort(true);
        loader.load();

        add(grid);   

      }




}


It seems your code is making a cross-domain request, thus using the ScriptTagProxy class would be more appropriate here. GXT documentation states:

Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜