Question

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

Was it helpful?

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/

OTHER TIPS

Window.Location.getParameter parses the URL's query-string into name-value pairs.

So Window.Location.getParameter("id") would return foo if the URL had id=3 in the query-string (e.g. ?id=foo or ?gwt.codesvr=127.0.0.1:9997&id=foo)

I don't know what XDOM is, but I guess XDOM.getBody().getId() is no different form Document.get().getBody().getId(), so it would return the value of an id attribute on the <body> element (e.g. <body id=foo>)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top