开发者

GWT - How to get a value and decide which page load

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) {
     开发者_StackOverflow中文版   if(History.getToken().equals("apartment")) {
            pageloader.clear();
            pageloader.add(new ApartmentContext(rpcService));
        } else {
            pageloader.clear();
            pageloader.add(new HomepageContext(rpcService));
        }
    }    
}

What's wrong?


i think you'll want to implement a ValueChangeHandler< String > , and work with History ( History.addValueChangeHandler( changeHandler ).

then, on your valuechangehandler implementation you can get the token requested and choose what view to show.

hope this helps :)


To do that you should first add a servlet (instead of the static html page) to serve your gwt application.

First step could be just add a servlet that return the current static html page with gwt iframe. You need also to change your web.xml of course.

Second step is to change the returned html according the url to show one gwt module or the other. This is the only solution if you want to show 2 different gwt applications (aka modules) according the url.

Anyway if I understood your question, what you want to do is just show different data using the url, for that I recommend another solution: use the # sign.

It's very easy with GWT to show different pages (inside a single GWT module) with this syntax. http://localhost:8084/GWT/index.html http://localhost:8084/GWT/index.html#page=2 http://localhost:8084/GWT/index.html#searchFor=foo etc.

look for Events and History in GWT documentation. This is also a very good starting point to have RESTish urls: http://code.google.com/webtoolkit/articles/mvp-architecture.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜