我試圖修改GWT 2.1 HelloMVP示例代碼以使用更復雜的用戶界面。 (由於兩個鏈接限制,我不允許提供鏈接)我如何使用ComplexPanel與GWT ActivityManager
我的問題是ActivityManager.setDisplay只接受實現AcceptsOneWidget的對象。 LayoutPanel和其他ComplexPanel不實現AcceptsOneWidget。示例代碼改爲使用SimplePanel。但我似乎無法在SimplePanel中嵌套複雜的Widget(它們不顯示)。
我發現對這個問題的一些討論:
人建議的解決方案是創建ComplexPanel的子類,我想實現的AcceptsOneWidget接口。像這樣:
public class PanelForView extends LayoutPanel implements AcceptsOneWidget {
IsWidget myWidget = null;
@Override
public void setWidget(IsWidget w) {
if (myWidget != w) {
if (myWidget != null) {
remove(myWidget);
}
if (w != null) {
add(w);
}
myWidget = w;
}
}
}
這聽起來不錯,但它似乎並不適合我。也許是因爲我使用的是GWT 2.3而不是2.1或2.2。在我的EntryPoint中,我希望簡單地將SimplePanel替換爲新的PanelForView類,並使應用程序像以前一樣運行。像這樣:
public class HelloMVP implements EntryPoint {
private Place defaultPlace = new HelloPlace("World!");
// private SimplePanel appWidget = new SimplePanel(); // Replace this with PanelForView
private PanelForView appWidget = new PanelForView(); // This compiles but doesn't work.
// private SimpleLayoutPanel appWidget = new SimpleLayoutPanel(); // This doesn't work either.
public void onModuleLoad() {
// Create ClientFactory using deferred binding so we can replace with different
// impls in gwt.xml
ClientFactory clientFactory = GWT.create(ClientFactory.class);
EventBus eventBus = clientFactory.getEventBus();
PlaceController placeController = clientFactory.getPlaceController();
// Start ActivityManager for the main widget with our ActivityMapper
ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
activityManager.setDisplay(appWidget);
// Start PlaceHistoryHandler with our PlaceHistoryMapper
AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
historyHandler.register(placeController, eventBus, defaultPlace);
RootPanel.get().add(appWidget);
// Goes to place represented on URL or default place
historyHandler.handleCurrentHistory();
}
}
編譯沒有問題,但是當我運行它,我什麼也看不見,但現在一個空白屏幕。有什麼額外的我必須做初始化一個ComplexPanel?我只是誤解了一些東西?我試着添加Widgets並調用setSize無濟於事。這是我的第一個GWT項目。
謝謝你的時間。
科瑞
嘗試刪除if語句'如果(進myWidget!= W)' – 2011-06-11 14:05:59