GWTP、PresenterWidget 和 Google Visualisation API 不会显示饼图



我是GWT-P的新手,但是关于这个主题的资料很少。我试图做一个简单的饼状图小部件,用于测试目的。我已经制作了Widget演示器、视图和UiBinder。

package com.rs.gwtp.gametestingyou.client;
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.View;
import com.google.inject.Inject;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.HTMLPanel;
public class PieChartPresenter extends
PresenterWidget<PieChartPresenter.MyView> {

public interface MyView extends View {
public HTMLPanel getChartPanel();
public void drawPieChart();
}
@Inject
public PieChartPresenter(final EventBus eventBus, final MyView view) {
super(eventBus, view);
}
@Override
protected void onBind() {
super.onBind();

}
/*Ovde prmeniti method*/
@Override
protected void onReset() {
super.onReset();
/*MyView v = getView();
v.drawPieChart();*/
getView().drawPieChart();
}
}

然后视图。

package com.rs.gwtp.gametestingyou.client;
import com.gwtplatform.mvp.client.ViewImpl;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.visualizations.corechart.Options;
import com.google.gwt.visualization.client.visualizations.corechart.PieChart;
import com.google.inject.Inject;
public class PieChartView extends ViewImpl implements PieChartPresenter.MyView {
private final Widget widget;
@UiField HTMLPanel chartPanel;
@UiField (provided=true) PieChart pieChart;
public interface Binder extends UiBinder<Widget, PieChartView> {
}
@Inject
public @UiConstructor PieChartView(final Binder binder) {
widget = binder.createAndBindUi(this);
pieChart = new PieChart(createTable(), createOptions());
chartPanel.add(pieChart);
}
@Override
public Widget asWidget() {
return widget;
}
public HTMLPanel getChartPanel(){
return chartPanel;
}
@Override
public void drawPieChart() {
// OVAJ POKUSAJ
pieChart.draw(createTable(),createOptions());
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
}

和最后一个ibinder

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default'
xmlns:c="urn:import:com.google.gwt.visualization.client.visualizations.corechart" xmlns:v="urn:import:com.google.gwt.visualization.client.visualizations">
<g:HTMLPanel ui:field="chartPanel">
<c:PieChart ui:field="pieChart" ></c:PieChart>
</g:HTMLPanel>
</ui:UiBinder>

当我加载这段代码时,我得到错误:[ERROR] [gametestingyou] -无法加载模块入口点类com.rs.gwtp.gametestingyou.client.GameTestingYou(参见相关异常)和Umbrella异常。

请帮忙:)!

This is full Exception:

19:14:34.890 [ERROR] [gametestingyou]无法加载模块入口点类com.rs.gwtp.gametestingyou.client.GameTestingYou(参见相关的异常详细信息)一个或多个捕获的异常,参见完整的设置在伞例外#getCausescom.google.gwt.event.shared.HandlerManager.fireEvent (HandlerManager.java: 129)com.google.gwt.user.client.impl.HistoryImpl.fireEvent (HistoryImpl.java: 75)com.google.gwt.event.logical.shared.ValueChangeEvent.fire (ValueChangeEvent.java: 43)com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl (HistoryImpl.java: 82)com.google.gwt.user.client.History.fireCurrentHistoryState (History.java: 121)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealCurrentPlace (PlaceManagerImpl.java: 310)在com.rs.gwtp.gametestingyou.client.GameTestingYou.onModuleLoad (GameTestingYou.java: 17)在sun.reflect.NativeMethodAccessorImpl。invoke0(本地方法)在sun.reflect.NativeMethodAccessorImpl。调用(未知源)在sun.reflect.DelegatingMethodAccessorImpl。调用(未知源)在java.lang.reflect.Method。调用(未知源)com.google.gwt.dev.shell.ModuleSpace.onLoad (ModuleSpace.java: 396)com.google.gwt.dev.shell.OophmSessionHandler.loadModule (OophmSessionHandler.java: 200)com.google.gwt.dev.shell.BrowserChannelServer.processConnection (BrowserChannelServer.java: 525)com.google.gwt.dev.shell.BrowserChannelServer.run (BrowserChannelServer.java: 363)在java.lang.Thread.run(来源未知)引起的原因:com.google.gwt.event.shared.UmbrellaException:捕获一个或多个异常,参见完整的设置在UmbrellaException#getCausescom.google.gwt.event.shared.EventBus.castFireEventFromSource (EventBus.java: 77)com.google.gwt.event.shared.SimpleEventBus.fireEventFromSource (SimpleEventBus.java: 67)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.fireEvent (PlaceManagerImpl.java: 146)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.doRevealPlace (PlaceManagerImpl.java: 121)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealPlace (PlaceManagerImpl.java: 339)在com.rs.gwtp.gametestingyou.client.place.ClientPlaceManager.revealDefaultPlace (ClientPlaceManager.java: 24)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.onValueChange (PlaceManagerImpl.java: 264)com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch (ValueChangeEvent.java: 128)com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch (ValueChangeEvent.java: 1)com.google.gwt.event.shared.GwtEvent.dispatch (GwtEvent.java: 1)com.google.web.bindery.event.shared.EventBus.dispatchEvent (EventBus.java: 40)com.google.web.bindery.event.shared.SimpleEventBus.doFire (SimpleEventBus.java: 193)com.google.web.bindery.event.shared.SimpleEventBus.fireEvent (SimpleEventBus.java: 88)com.google.gwt.event.shared.HandlerManager.fireEvent (HandlerManager.java: 127)com.google.gwt.user.client.impl.HistoryImpl.fireEvent (HistoryImpl.java: 75)com.google.gwt.event.logical.shared.ValueChangeEvent.fire (ValueChangeEvent.java: 43)com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl (HistoryImpl.java: 82)com.google.gwt.user.client.History.fireCurrentHistoryState (History.java: 121)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealCurrentPlace (PlaceManagerImpl.java: 310)在com.rs.gwtp.gametestingyou.client.GameTestingYou.onModuleLoad (GameTestingYou.java: 17)在sun.reflect.NativeMethodAccessorImpl。invoke0(本地方法)在sun.reflect.NativeMethodAccessorImpl。调用(未知源)在sun.reflect.DelegatingMethodAccessorImpl。调用(未知源)在java.lang.reflect.Method。调用(未知源)com.google.gwt.dev.shell.ModuleSpace.onLoad (ModuleSpace.java: 396)com.google.gwt.dev.shell.OophmSessionHandler.loadModule (OophmSessionHandler.java: 200)com.google.gwt.dev.shell.BrowserChannelServer.processConnection (BrowserChannelServer.java: 525)com.google.gwt.dev.shell.BrowserChannelServer.run (BrowserChannelServer.java: 363)在java.lang.Thread.run(来源未知)原因:java.lang.NullPointerException: nullcom.google.gwt.user.client.ui.HTMLPanel.addAndReplaceElement (HTMLPanel.java: 197)com.rs.gwtp.gametestingyou.client.PieChartView_BinderImpl.createAndBindUi (PieChartView_BinderImpl.java: 33)com.rs.gwtp.gametestingyou.client.PieChartView_BinderImpl.createAndBindUi (PieChartView_BinderImpl.java: 1)在com.rs.gwtp.gametestingyou.client.PieChartView。(PieChartView.java: 27)在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.com rs gwtp gametestingyou美元美元客户PieChartView_PieChartView_methodInjection美元(ClientGinjectorImpl.java: 555)在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key类型com rs gwtp美元美元gametestingyou端PieChartView _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 559)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key类型com rs gwtp美元美元gametestingyou端PieChartView _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 570)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key类型com rs gwtp美元美元gametestingyou端PieChartPresenter MyView _annotation美元美元美元$ $ $ $ (ClientGinjectorImpl.java: 1726)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key类型com rs gwtp美元美元gametestingyou端PieChartPresenter MyView _annotation美元美元美元$ $ $ $ (ClientGinjectorImpl.java: 1735)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key类型com rs gwtp美元美元gametestingyou端PieChartPresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 1522)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key类型com rs gwtp美元美元gametestingyou端PieChartPresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 1533)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.memberInject_Key类型com rs gwtp美元美元gametestingyou端ShowTestResultsPresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 2069)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key类型com rs gwtp美元美元gametestingyou端ShowTestResultsPresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 2079)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key类型com rs gwtp美元美元gametestingyou端ShowTestResultsPresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 2092)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.memberInject_Key类型com rs gwtp美元美元gametestingyou端HomePagePresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 1341)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.create_Key类型com rs gwtp美元美元gametestingyou端HomePagePresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 1352)没有一个在com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.get_Key类型com rs gwtp美元美元gametestingyou端HomePagePresenter _annotation美元美元$ $ $ $ (ClientGinjectorImpl.java: 1365)没有一个com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl.access 4美元(ClientGinjectorImpl.java: 1363)com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl 5美元1.美元onsuccess (ClientGinjectorImpl.java: 1413)com.google.gwt.core.client.GWT.runAsync (GWT.java: 255)com.rs.gwtp.gametestingyou.client.gin.ClientGinjectorImpl得到5.美元(ClientGinjectorImpl.java: 1411)在com.gwtplatform.common.client.CodeSplitProvider.get (CodeSplitProvider.java: 48)com.gwtplatform.mvp.client.proxy.ProxyImpl.getPresenter (ProxyImpl.java: 46)com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract.handleRequest (ProxyPlaceAbstract.java: 193)com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract.access $ 0 (ProxyPlaceAbstract.java: 192)com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract onplacerequest 1.美元(ProxyPlaceAbstract.java: 143)com.gwtplatform.mvp.client.proxy.PlaceRequestInternalEvent.dispatch (PlaceRequestInternalEvent.java: 134)com.gwtplatform.mvp.client.proxy.PlaceRequestInternalEvent.dispatch (PlaceRequestInternalEvent.java: 1)com.google.gwt.event.shared.GwtEvent.dispatch (GwtEvent.java: 1)com.google.web.bindery.event.shared.EventBus.dispatchEvent (EventBus.java: 40)com.google.web.bindery.event.shared.SimpleEventBus.doFire (SimpleEventBus.java: 193)com.google.web.bindery.event.shared.SimpleEventBus.fireEventFromSource (SimpleEventBus.java: 96)com.google.gwt.event.shared.SimpleEventBus.fireEventFromSource (SimpleEventBus.java: 62)com.google.gwt.event.shared.EventBus.castFireEventFromSource (EventBus.java: 75)com.google.gwt.event.shared.SimpleEventBus.fireEventFromSource (SimpleEventBus.java: 67)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.fireEvent (PlaceManagerImpl.java: 146)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.doRevealPlace (PlaceManagerImpl.java: 121)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealPlace (PlaceManagerImpl.java: 339)在com.rs.gwtp.gametestingyou.client.place.ClientPlaceManager.revealDefaultPlace (ClientPlaceManager.java: 24)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.onValueChange (PlaceManagerImpl.java: 264)com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch (ValueChangeEvent.java: 128)com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch (ValueChangeEvent.java: 1)com.google.gwt.event.shared.GwtEvent.dispatch (GwtEvent.java: 1)com.google.web.bindery.event.shared.EventBus.dispatchEvent (EventBus.java: 40)com.google.web.bindery.event.shared.SimpleEventBus.doFire (SimpleEventBus.java: 193)com.google.web.bindery.event.shared.SimpleEventBus.fireEvent (SimpleEventBus.java: 88)com.google.gwt.event.shared.HandlerManager.fireEvent (HandlerManager.java: 127)com.google.gwt.user.client.impl.HistoryImpl.fireEvent (HistoryImpl.java: 75)com.google.gwt.event.logical.shared.ValueChangeEvent.fire (ValueChangeEvent.java: 43)com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl (HistoryImpl.java: 82)com.google.gwt.user.client.History.fireCurrentHistoryState (History.java: 121)com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.revealCurrentPlace (PlaceManagerImpl.java: 310)在com.rs.gwtp.gametestingyou.client.GameTestingYou.onModuleLoad (GameTestingYou.java: 17)在sun.reflect.NativeMethodAccessorImpl。invoke0(本地方法)在sun.reflect.NativeMethodAccessorImpl。调用(未知源)在sun.reflect.DelegatingMethodAccessorImpl。调用(未知源)在java.lang.reflect.Method。调用(未知源)com.google.gwt.dev.shell.ModuleSpace.onLoad (ModuleSpace.java: 396)com.google.gwt.dev.shell.OophmSessionHandler.loadModule (OophmSessionHandler.java: 200)com.google.gwt.dev.shell.BrowserChannelServer.processConnection (BrowserChannelServer.java: 525)com.google.gwt.dev.shell.BrowserChannelServer.run (BrowserChannelServer.java: 363)在java.lang.Thread.run(未知来源)

package com.rs.gwtp.gametestingyou.client;
import com.google.gwt.core.client.EntryPoint;
import com.rs.gwtp.gametestingyou.client.gin.ClientGinjector;
import com.google.gwt.core.client.GWT;
import com.gwtplatform.mvp.client.DelayedBindRegistry;

public class GameTestingYou implements EntryPoint {
private final ClientGinjector ginjector = GWT.create(ClientGinjector.class);
@Override
public void onModuleLoad() {
// This is required for Gwt-Platform proxy's generator
DelayedBindRegistry.bind(ginjector);
ginjector.getPlaceManager().revealCurrentPlace();   
}
}

在构造函数中尝试在调用createAndBindUi之前初始化pieChart

@Inject
public @UiConstructor PieChartView(final Binder binder) {
pieChart = new PieChart(createTable(), createOptions());
widget = binder.createAndBindUi(this);
chartPanel.add(pieChart);
}

我发现这个问题是GWT-P特有的,因为EntryPoint类没有加载所需的包。它需要用这个方法加载VisualizationUtils。loadVisualizationApi (onLoadCallback PieChart.PACKAGE);并将可运行接口添加到实现EntryPoint类的类中,如以下示例:

Runnable onLoadCallback = new Runnable() {
@Override
public void run() {
PieChart pieChart = new PieChart(createTable(), createOptions());
Panel panel = RootPanel.get();
panel.add(pieChart);
}
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}

};

,但这将添加,在这个例子中,pieChart,到RootPanel,刚刚弄清楚如何将这个对象pieChart添加到特定的presententerwidget。当我这样做的时候,我会做一个教程:)

成功!!这就是我如何最终完成我的意图:添加一些图表到现有的GWT-P项目。当我确定API设置良好时,我发现这是解决方案:

UiBinder只需要有HTML表:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default'     xmlns:c="urn:import:com.google.gwt.visualization.client.visualizations.corechart" 
xmlns:v="urn:import:com.google.gwt.visualization.client.visualizations">
<g:HTMLPanel ui:field="chartPanel">
</g:HTMLPanel>
</ui:UiBinder>

Then View应该像这样简单:

public class PieChartView extends ViewImpl implements PieChartPresenter.MyView {
private final Widget widget;
@UiField HTMLPanel chartPanel;
public interface Binder extends UiBinder<Widget, PieChartView> {
}
@Inject
public @UiConstructor PieChartView(final Binder binder) {   
widget = binder.createAndBindUi(this);
}
@Override
public Widget asWidget() {
return widget;
}
public HTMLPanel getChartPanel(){
return chartPanel;
}

}

然后PresenterWidget,需要通过VisualizationUtils加载适当的包。loadVisualizationApi (onLoadCallback PieChart.PACKAGE);这样的:

public class PieChartPresenter extends
PresenterWidget<PieChartPresenter.MyView> {
public interface MyView extends View {
public HTMLPanel getChartPanel();
}
@Inject
public PieChartPresenter(final EventBus eventBus, final MyView view) {
super(eventBus, view);
}
@Override
protected void onBind() {
super.onBind();
Runnable onLoadCallback = new Runnable() {
@Override
public void run() {
PieChart pieChart = new PieChart(createTable(), createOptions());
/*Panel panel = RootPanel.get();*/
/*panel.add(pieChart);*/
Panel panel = getView().getChartPanel();
panel.add(pieChart);
}
private AbstractDataTable createTable() {
DataTable data = DataTable.create();
data.addColumn(ColumnType.STRING, "Task");
data.addColumn(ColumnType.NUMBER, "Hours per Day");
data.addRows(2);
data.setValue(0, 0, "Work");
data.setValue(0, 1, 14);
data.setValue(1, 0, "Sleep");
data.setValue(1, 1, 10);
return data;
}
private Options createOptions() {
Options options = Options.create();
options.setWidth(400);
options.setHeight(240);
options.setTitle("My Daily Activities");
return options;
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
}
/*Ovde prmeniti method*/
@Override
protected void onReset() {
super.onReset();
}

}

现在这只是为了测试的目的,这是我想要的结果:将PieChart放在presententerwidget中并在调用时呈现它。

相关内容

  • 没有找到相关文章

最新更新