【问题标题】:Window Location getParameter is always null in GWT/GXT Project?GWT/GXT 项目中的窗口位置 getParameter 始终为空?
【发布时间】:2014-06-14 00:59:12
【问题描述】:

我正在工作 GWT/GXT 我正在尝试练习一些示例。

这是项目的网址

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;
        }

谁能告诉我String id = Window.Location.getParameter("id"); 是什么,setParameter 的Windows.Location 是什么@

什么是id = XDOM.getBody().getId();

我的 ID 为空。

【问题讨论】:

    标签: gwt gwt2 gxt


    【解决方案1】:

    在EntryPoint 类中添加以下代码

    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);
            }
        }
    }
    

    我的url中没有&id=foo,如何在url中添加呢?


    如何获取主机页面的基本 URL?

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

    【讨论】:

      【解决方案2】:

      Window.Location.getParameter 将 URL 的查询字符串解析为名称-值对。

      因此,如果 URL 在查询字符串中包含 id=3(例如 ?id=foo 或 ?gwt.codesvr=127.0.0.1:9997&amp;id=foo),Window.Location.getParameter("id") 将返回 foo

      我不知道XDOM 是什么,但我猜XDOM.getBody().getId() 与Document.get().getBody().getId() 没有什么不同,所以它会返回&lt;body&gt; 元素上的id 属性的值(例如@987654332 @)

      【讨论】:

      • 我的url中没有&amp;id=foo,如何在url中添加呢?当我运行应用程序时,我得到这个 URL http://127.0.0.1:8888/Opera_Star.html?gwt.codesvr=127.0.0.1:9997
      猜你喜欢
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 2018-05-24
      • 2011-06-09
      • 2015-12-04
      相关资源
      最近更新 更多