Search code examples
gwtgwt2gxt

Window Location getParameter is always null in GWT/GXT Project?


I am working GWT/GXT I am trying to practise some sample Examples.

This is url of the project

http://127.0.0.1:8888/Opera_Star.html?gwt.codesvr=127.0.0.1:9997

public void onModuleLoad() {
        Map<String, Entry> project = new FastMap<Entry>();
        ProjectModel projectModel = new ProjectModel();
        for (int i = 0; i < projectModel.getChildren().size(); i++) {// 1 children
            LoginCategory loginCategory = (LoginCategory) projectModel
                    .getChildren().get(i);
            for (int j = 0; j < loginCategory.getChildren().size(); j++) {// 2 children
                Entry entry = (Entry) loginCategory.getChildren().get(j);
                project.put(entry.getId(), entry);
            }
        }   
        Registry.register(MODEL, projectModel);
        String id = Window.Location.getParameter("id");
        if (id == null) {
            id = XDOM.getBody().getId();
        }    
        Entry entry = project.get(id);    
        if (entry == null) {
            return;
        }

Can Anybody tell me What is String id = Window.Location.getParameter("id");, How to setParameter for Windows.Location

What is id = XDOM.getBody().getId();

I am getting Id null.

enter image description here


Solution

  • Add below code in your EntryPoint class

    private static Map<String, String> queryParams = new HashMap<String, String>();
    
    static {
        Map<String, List<String>> paramsMap = Window.Location.getParameterMap();
        for (String key : paramsMap.keySet()) {
            List<String> values = paramsMap.get(key);
            if (values.size() > 0) {
                String value = values.get(0);
                queryParams.put(key.toLowerCase(), value);
                queryParams.put(key, value);
            }
        }
    }
    

    I dont have &id=foo in the url, how to add it in the URL?


    How to get the host page base URL?

    GWT.getHostPageBaseURL(); //http://127.0.0.1:8888/