【问题标题】:GWT - Browser based Conditional CompilationGWT - 基于浏览器的条件编译
【发布时间】:2011-03-06 07:04:27
【问题描述】:

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

等等

【问题讨论】:

    标签: java gwt conditional-compilation


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      相关资源
      最近更新 更多