问题
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.
回答1:
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?
Change URL in browser address bar without reload existing page
Modify the URL without reloading the page
How to get the host page base URL?
GWT.getHostPageBaseURL(); //http://127.0.0.1:8888/
回答2:
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>)
来源:https://stackoverflow.com/questions/23341793/window-location-getparameter-is-always-null-in-gwt-gxt-project