Ext-GWT (GXT) 简单 REST 尝试不起作用
我正在尝试获取一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您的代码正在发出跨域请求,因此使用 ScriptTagProxy 类在这里更合适。 GXT 文档指出:
It seems your code is making a cross-domain request, thus using the ScriptTagProxy class would be more appropriate here. GXT documentation states: