I need to know (by using GWT) the strategy of how load some class instead of some others according to HTTP GET value.
Example :
// Main.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User"/>
<entry-point class="org.sinfonet.client.PageLoader"/>
</module>
// PageLoader
package org.sinfonet.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class PageLoader implements EntryPoint {
public void onModuleLoad() {
FlowPanel pageloader=new FlowPanel();
pageloader.add(new MainHomePage());
RootPanel.get().add(pageloader);
}
}
If my GET
is http://localhost:8084/GWT/index.html
, i would like to load MainHomePage()
;
Else, if my GET
is http://localhost:8084/GWT/index.html?page=2
, i would like to load MainAnotherClass()
;
I need to implements this on PageLoader class, on XML, or where? I think on xml, because PageLoader is a client-side class...there is no way to take a decision here.
P.S. I want to load another page (alias, another main Class), not load it dinamically.
EXAMPLE I TRIED
Thanks to Chris Boesing
of this solution, i found an easy piece of code that do what i need. Unfortunatly somethings is wrong, because it call the .clear()
method, but it doesnt append my new container. That's the code :
public class PageLoader implements EntryPoint, ValueChangeHandler<String> {
private FlowPanel pageloader;
private GWTServiceAsync rpcService;
public void onModuleLoad() {
pageloader=new FlowPanel();
rpcService=GWT.create(GWTService.class);
pageloader.add(new HomepageContext(rpcService));
RootPanel.get().add(pageloader);
History.addValueChangeHandler(this);
if(!History.getToken().isEmpty()){
changePage(History.getToken());
}
}
public void onValueChange(ValueChangeEvent event) {
changePage(History.getToken());
}
public void changePage(String token) {
if(History.getToken().equals("apartment")) {
pageloader.clear();
pageloader.add(new ApartmentContext(rpcService));
} else {
pageloader.clear();
pageloader.add(new HomepageContext(rpcService));
}
}
}
What's wrong?