我正在https://code.google.com/p/gwt-platform/wiki/GettingStarted#Embedding_a_GWTP_app_in_a_webpage
开始为我添加RootPresenter的代码时的一些原因:
`
public class MyRootPresenter extends RootPresenter {
public static final class MyRootView extends RootView {
@Override
public void setInSlot(Object slot, IsWidget widget) {
RootPanel.get("content").add(widget);
}
}
@Inject
public MyRootPresenter( EventBus eventBus, MyRootView myRootView ) {
super( eventBus, myRootView );
}
}
`
只有<.. id="content"></ ..>
这是正确的,它才会显示应用。但是,当我添加该元素,并从一个页面转到另一个页面时,它不会从html中删除旧的演示者。
我的GinInjector:
`
@GinModules({ MyModule.class })
public interface MyGinjector extends Ginjector {
PlaceManager getPlaceManager();
EventBus getEventBus();
AsyncProvider<MainPagePresenter> getMainPagePresenter();
AsyncProvider<NextPagePresenter> getNextPagePresenter();
}
`
MyModule的: `
public class MyModule extends AbstractPresenterModule {
@Override
protected void configure() {
// install(new DefaultModule(MyPlaceManager.class));
install(new CommonGinModule());
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
bind(TokenFormatter.class).to(ParameterTokenFormatter.class).in(Singleton.class);
bind(RootPresenter.class).to(MyRootPresenter.class).asEagerSingleton();
bind(PlaceManager.class).to(MyPlaceManager.class).in(Singleton.class);
bind(GoogleAnalytics.class).to(GoogleAnalyticsImpl.class).in(Singleton.class);
// Presenters
bindPresenter(MainPagePresenter.class,
MainPagePresenter.MyView.class,
MainPageView.class,
MainPagePresenter.MyProxy.class
);
bindPresenter(NextPagePresenter.class,
NextPagePresenter.MyNextView.class,
NextPageView.class,
NextPagePresenter.MyNextProxy.class);
}
}
`
Mypresenter(另一个很像这样): `
public class MainPagePresenter extends
Presenter<MainPagePresenter.MyView, MainPagePresenter.MyProxy> {
public interface MyView extends View {
}
@ProxyCodeSplit
@NameToken("main")
public interface MyProxy extends ProxyPlace<MainPagePresenter> {}
@Inject
public MainPagePresenter(EventBus eventBus, MyView view, MyProxy proxy) {
super(eventBus, view, proxy);
}
@Override
protected void revealInParent() {
RevealRootContentEvent.fire( this, this );
}
}
`
并查看:
public class MainPageView extends ViewImpl implements MainPagePresenter.MyView {
private static String html =
"<h1>Web Application Starter Project</h1>\n" +
"<table align=\"center\">\n" +
" <tr>\n" +
" <td colspan=\"2\" style=\"font-weight:bold;\">Please enter your name:</td>\n" +
" </tr>\n" +
" <tr>\n" +
" <td id=\"nameFieldContainer\"></td>\n" +
" <td id=\"sendButtonContainer\"></td>\n" +
" </tr>\n" +
" <tr>\n" +
" <td colspan=\"2\" style=\"color:red;\" id=\"errorLabelContainer\"></td>\n" +
" </tr>\n" +
"</table>\n";
HTMLPanel panel = new HTMLPanel(html);
@Inject
public MainPageView(final PlaceManager myPlaceManager) {
final Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();
// We can add style names to widgets
sendButton.addStyleName("sendButton");
sendButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
PlaceRequest request = new PlaceRequest("next");
myPlaceManager.revealPlace(request);
}
});
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
panel.add(nameField, "nameFieldContainer");
panel.add(sendButton, "sendButtonContainer");
panel.add(errorLabel, "errorLabelContainer");
}
@Override
public Widget asWidget() {
return panel;
}
}
阅读入门页面,应该非常简单。但有些如何,它不能正常工作。