GWT代码如何在开发代码中运行 [英] How GWT code runs in development code

查看:97
本文介绍了GWT代码如何在开发代码中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GWT网页/制作模式下,Java代码被编译成在浏览器中呈现的Javascript代码。



另外,我一直认为在GWT开发模式,GWT开发人员插件将我的Java代码编译为JavaScript以在浏览器中呈现它。但是在阅读了某个网站之后,我开始知道没有编写JavaScript代码来在浏览器中以开发模式查看它。

所以,我想知道:在这种模式下,如果他们不是JavaScript代码,我是否会在浏览器中看到这些小部件?我不明白这一点。



请帮助理解这一点。

解决方案

<开发模式的关键在于您的代码以Java运行。如果您可以使用标准的Java调试器,这是一个先决条件。您可以在 GWT文档中找到高级概述。 。



神奇的发生在 JSNI方法覆盖类型:当一个类是所有的JSNI方法都被提取出来,并且它们的JS主体被发送到浏览器,随时可以执行(然后作为JavaScript),并且该类被动态地重写 以重新实现JSNI方法一个调用浏览器(通过在那里安装的Dev Plugin,由URL中的?gwt.codesvr = 触发)来执行相应的操作JS功能。这就是Java对象在JSNI方法中被看作不透明句柄的原因;他们被分配一个数字ID来将Java对象与服务器端的虚拟JS对象配对。类似的,虽然更复杂的重写是针对覆盖类型完成的,并且当JS对象被传递给Java代码时使用相同的ID映射(作为覆盖类型)。

超级开发模式即时编译为JavaScript(几乎) em>。


In GWT web/production mode, Java code is complied into Javascript code that is rendered in the browser.

Also,I have always thought that in GWT development mode, GWT developer plugin compiles my Java code into JavaScript to render it in the browser. But after reading on some site, I came to know that there's no compiling of code to JavaScript to view it in the browser in development mode.

So, I wonder: What are all these widgets I see in the browser during this mode if they aren't JavaScript code?. I don't understand it.

Please help understanding this.

解决方案

The crux of the Dev Mode is that your code runs in Java. This is a prerequisite if you can use a standard Java debugger. You'll find a high-level overview in the GWT documentation.

The magic happens with JSNI methods and overlay types: when a class is loaded, all its JSNI methods are extracted and their JS body is sent to the browser, ready to be executed (as JavaScript then), and the class is rewritten on the fly to reimplement the JSNI method to make a call to the browser (via the Dev Plugin you installed there and is triggered by ?gwt.codesvr= in the URL) to execute the corresponding JS function. This is the reason why Java objects are seen as opaque handles in JSNI methods; they're assigned a numeric ID to pair the Java object with a dummy JS object on the server-side. A similar though more complex rewriting is done for overlay types, and the same ID mapping is used when JS objects are passed to Java code (as overlay types).

BTW, Super Dev Mode compiles to JavaScript (almost) on the fly.

这篇关于GWT代码如何在开发代码中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆