#working application in 4 classes
Hello World Application
This application doesn't actually print Hello World because we will be demonstrating a few more elements of GWT Pages then a true simple Hello World application would allow.
Create a Constants Class for Page Tokens
While this isn't necessary it is strongly recommended
public interface PageConstants {
public static final String ANOTHER_PAGE = "another";
}Create the Start Page
public class StartPage extends FlowPanel implements Page, ClickHandler {
private TextBox parameter1;
private TextBox parameter2;
public StartPage() {
// allow the user to enter a couple of parameters
add(new Label("Parameter 1"));
add(this.parameter1 = new TextBox());
add(new HTML("<br/>"));
add(new Label("Parameter 1"));
add(this.parameter2 = new TextBox());
add(new HTML("<br/>"));
add(new Button("Click Me", this));
}
@Override
public void onClick(ClickEvent event) {
// go to another page and add some parameters
Pages.get().gotoPage(
PageConstants.ANOTHER_PAGE,
parameter1.getText(),
parameter2.getText())
.execute();
}
@Override
public void onEnterPage(PageParameters parameters,
PageRequestSession session, AsyncPageCallback callback) {
// we don't need to do anything when the page shows up
}
@Override
public void onExitPage() {
parameter1.setText(null);
parameter2.setText(null);
}
@Override
public void init(Pages settings) {
}
@Override
public Widget asWidget() {
return this;
}
}Create Another Page
public class AnotherPage extends FlowPanel implements Page {
private Label parametersLbl;
public AnotherPage() {
add(new Label("The parameters are: "));
add(this.parametersLbl = new Label());
}
@Override
public void onEnterPage(PageParameters parameters,
PageRequestSession session, AsyncPageCallback callback) {
StringBuilder sb = new StringBuilder();
for (int i=0; i<parameters.listSize(); i++) {
if (sb.length() > 0) sb.append(", ");
sb.append(parameters.asString(i));
}
parametersLbl.setText(sb.toString());
}
@Override
public void onExitPage() {
}
@Override
public void init(Pages settings) {
}
@Override
public Widget asWidget() {
return this;
}
}Create the Page Loader
public class MyPageLoader extends StandardPageLoader {
@Override
public void registerPages() {
// register the pages we will use
registerPage(PAGE_DEFAULT, StartPage.class);
registerPage(PageConstants.ANOTHER_PAGE, AnotherPage.class);
}
}Create the Entry Point
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// create the application presenter and add it to the root (this is the simplest of them)
SimplePanelApplicationPresenter applicationPresenter = new SimplePanelApplicationPresenter();
RootPanel.get().add(applicationPresenter);
// initialize the pages settings
Pages.init(
(MyPageLoader) GWT.create(MyPageLoader.class),
applicationPresenter,
new HandlerManager(null), // the event bus
true) // we want to listen to history tokens
.addDefaultEventHandlers() // add default behavior if desired
.showStartPage(true); // show the first page while checking the history token
}
}
Where can I get gwtpages project library/jar file? I coulnd't find it anywhere.
Thanks.
Yin