2010-06-21 57 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文檔。