GWT - 基于浏览器的条件编译

发布于 2024-09-06 06:31:40 字数 330 浏览 8 评论 0原文

有没有办法告诉 GWT 针对每个目标浏览器编译不同的 Java 代码?

GWT 现在为每个目标浏览器创建不同的脚本,所有脚本均由同一源文件生成。然而,当在不同浏览器中使用非标准功能时(例如,将文件拖放到浏览器中),不同浏览器之间的支持差异很大,需要编写不同的代码。

有没有类似之类的

// if IE 
.. some Java code to compile into the IE script
// else if chrome
.. some Java code to compile into the chrome script

东西

is there a way to tell GWT to compile different Java code per target browser?

GWT today creates a different script per target browser, all generated from the same source file. However, when working with non-standard features in different browsers (for example, file drag and drop into the browser), the support is quite different between different browsers, requiring to write different code.

Is there something like

// if IE 
.. some Java code to compile into the IE script
// else if chrome
.. some Java code to compile into the chrome script

etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对风讲故事 2024-09-13 06:31:40

是的,当然。这就是所谓的延迟绑定。请查看 http://code.google.com/webtoolkit/doc/latest/ DevGuideCodingBasicsDeferred.html

这是摘录

<module>

  <!--  ... other configuration omitted ... -->

  <!-- Fall through to this rule is the browser isn't IE or Mozilla -->
  <replace-with class="com.google.gwt.user.client.ui.impl.PopupImpl">
    <when-type-is class="com.google.gwt.user.client.ui.impl.PopupImpl"/>
  </replace-with>

  <!-- Mozilla needs a different implementation due to issue #410 -->
  <replace-with class="com.google.gwt.user.client.ui.impl.PopupImplMozilla">
    <when-type-is class="com.google.gwt.user.client.ui.impl.PopupImpl" />
    <any>
      <when-property-is name="user.agent" value="gecko"/>
      <when-property-is name="user.agent" value="gecko1_8" />
    </any>
  </replace-with>

  <!-- IE has a completely different popup implementation -->
  <replace-with class="com.google.gwt.user.client.ui.impl.PopupImplIE6">
    <when-type-is class="com.google.gwt.user.client.ui.impl.PopupImpl"/>
    <when-property-is name="user.agent" value="ie6" />
  </replace-with>
</module>

对于其他浏览器,我相信它可以在没有失败规则的情况下工作。我认为失败规则的存在只是为了加快事情的进展。不要认为这是理所当然的,因为我不是 100% 确定。

这是来自 GWT 官方文档。

Yes, off course. The thing is called deferred binding. Check out http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html

Here's an excerpt

<module>

  <!--  ... other configuration omitted ... -->

  <!-- Fall through to this rule is the browser isn't IE or Mozilla -->
  <replace-with class="com.google.gwt.user.client.ui.impl.PopupImpl">
    <when-type-is class="com.google.gwt.user.client.ui.impl.PopupImpl"/>
  </replace-with>

  <!-- Mozilla needs a different implementation due to issue #410 -->
  <replace-with class="com.google.gwt.user.client.ui.impl.PopupImplMozilla">
    <when-type-is class="com.google.gwt.user.client.ui.impl.PopupImpl" />
    <any>
      <when-property-is name="user.agent" value="gecko"/>
      <when-property-is name="user.agent" value="gecko1_8" />
    </any>
  </replace-with>

  <!-- IE has a completely different popup implementation -->
  <replace-with class="com.google.gwt.user.client.ui.impl.PopupImplIE6">
    <when-type-is class="com.google.gwt.user.client.ui.impl.PopupImpl"/>
    <when-property-is name="user.agent" value="ie6" />
  </replace-with>
</module>

For the other browsers, I believe it would work without the fall through rule. I think the fall through rule is here just to speed up the things. Don't take this for granted, as I am not 100% sure.

This is from the official GWT documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文