首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GWT布局-如何使用docklayout

GWT布局-如何使用docklayout
EN

Stack Overflow用户
提问于 2012-06-23 23:37:51
回答 1查看 188关注 0票数 0

我正在使用GWT编写一个简单的应用程序。我使用dockPanel将视图划分为不同的部分。我需要在dockPanel的某个面板中调用一个调用facebook功能的脚本。下面是用Java编写的代码

代码语言:javascript
复制
public class XXXX implements EntryPoint 
{
private DockLayoutPanel dock = new DockLayoutPanel(Unit.PX); 
private HorizontalPanel navPanel = new HorizontalPanel();
private VerticalPanel fbPanel = new VerticalPanel();
private HorizontalPanel ratingsPanel = new HorizontalPanel();
private Marker m = null;
private InfoWindow iw = null;
MapWidget map= null;

public void onModuleLoad() 
{
    implementDockPanelLayout();
    implementMapView();

        // Add the facebook Javascript script to the fbPanel of the dock
    injectFBInitCode();
    RootLayoutPanel.get().add(dock);
}


private void implementDockLayoutSetup() 
{
        navPanel.add(new HTML("<h3>Navigation Panel</h3>"));
    fbPanel.add(new HTML("<div id = \"fb-root\"><h3>FB Comments should go here </h3></div>"));
    ratingsPanel.add(new HTML("<h3>Ratings Here</h3>"));
    dock.addNorth(navPanel, 50);
    dock.addEast(fbPanel, 300);
    dock.addSouth(ratingsPanel, 50);
}


private native void injectFBInitCode() /*-{
//??How to associate this script with the fbPanel which contains 
    the div with id= fb-root
function(d, s, id) 
{
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=XXXXXX";
    fjs.parentNode.insertBefore(js, fjs);
}
(document, 'script', 'facebook-jssdk');
}-*/;

private void implementMapView() 
     {
      ...}

当我运行上面的代码时,我在浏览器中得到一个异常:

代码语言:javascript
复制
  08:29:05.514 [ERROR] [SomeProj] Unable to load module entry point class  XXX.client.SomeProj (see associated exception for details)
 com.google.gwt.core.client.JavaScriptException: (null): null
 at   com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
 at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
 at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
 at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
 at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
 at cs310.client.someProj.injectFBInitCode(someProj.java)
 at cs310.client.someProj.onModuleLoad(someProj.java:53)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
 at  com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
 at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
 at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
 at java.lang.Thread.run(Thread.java:680)

我不太熟悉如何在GWT代码中调用Javascript函数。我查看了教程和一些示例,并编写了以下代码。但是我被卡住了,

有人能帮我一下吗。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-24 01:33:06

在JSNI中,您需要使用变量'$wnd‘来访问实际的窗口。所以你应该调用'$wnd.document‘

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11170769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档