Ext-GWT (GXT) 简单 REST 尝试不起作用

发布于 2024-11-01 06:08:08 字数 3710 浏览 1 评论 0原文

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

我找到了以下在线示例,在我的一生中,我无法理解为什么我的桌子没有被填充。它也看起来好像没有检索到数据。我将不胜感激任何帮助!谢谢。

/*
 * Ext GWT 2.2.3 - Ext for GWT
 * Copyright(c) 2007-2010, Ext JS, LLC.
 * [email protected]
 * 
 * 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);   

      }




}

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.
 * [email protected]
 * 
 * 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);   

      }




}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2024-11-08 06:08:08

看来您的代码正在发出跨域请求,因此使用 ScriptTagProxy 类在这里更合适。 GXT 文档指出:

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文