2010-06-21 55 views
2

有没有办法告诉GWT为每个目标浏览器编译不同的Java代码?GWT - 基于浏览器的条件编译

GWT今天为每个目标浏览器创建了一个不同的脚本,全部使用相同的源文件生成。但是,当使用不同浏览器中的非标准功能(例如,将文件拖放到浏览器中)时,不同浏览器之间的支持是完全不同的,需要编写不同的代码。

有什么样

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

回答

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文档。