2

有没有办法告诉 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

等等

4

1 回答 1

11

是的,当然。这个东西叫做延迟绑定。查看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 文档。

于 2010-06-21T13:15:12.690 回答