Ext-GWT(GXT)简单REST尝试无效

时间:2011-04-13 16:13:58

标签: rest gxt

我正在尝试使用简单的GXT应用程序从外部服务器检索数据。

我找到了以下example online,对于我的生活,我无法理解为什么我的桌子没有被填充。它看起来好像没有检索到数据。我将不胜感激任何帮助!谢谢。

/*
 * 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")
public 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);   

      }




}

1 个答案:

答案 0 :(得分:1)

您的代码似乎正在发出跨域请求,因此使用ScriptTagProxy类会更合适。 GXT文档说明:

  

请注意,如果要从域中 NOT 与运行页面的原始域相同的页面检索数据,则必须使用此类,而不是HttpProxy。 / p>