GWT模块XML - 如何重新定义和使用多个用户代理

时间:2022-09-23 08:00:34

http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_CompileOnePermutation

In the article I learned I can speed up the compiler but specifying the target user agent. The problem how can I specify more than one user agent? Suppose my application supports ie6 and FF3

在我学到的文章中,我可以加速编译器,但指定目标用户代理。问题如何指定多个用户代理?假设我的应用程序支持ie6和FF3

<set-property name="user.agent" value="ie6,geck1_8" />

doesn't work - I got XML parsing error:

不起作用 - 我得到XML解析错误:

[ERROR] Invalid property value 'ie6,gecko1_8'

I'm wondering if there's a way to specify more than one specific user agent in the module XML file?

我想知道是否有办法在模块XML文件中指定多个特定用户代理?

5 个解决方案

#1


I've had a similar error message, when setting the user.agent value to gecko in GWT2.4. So I looked around and found where the gwt code defines the possible values.

在GWT2.4中将user.agent值设置为gecko时,我遇到了类似的错误消息。所以我环顾四周,发现gwt代码定义了可能的值。

If you look in the gwt-user.jar at com.google.gwt.user.UserAgent.gwt.xml you can see the possible values for the version of GWT you are using.

如果您查看com.google.gwt.user.UserAgent.gwt.xml中的gwt-user.jar,您可以看到您正在使用的GWT版本的可能值。

For GWT2.4, this is what i found:

对于GWT2.4,这是我发现的:

<!-- Browser-sensitive code should use the 'user.agent' property -->
  <define-property name="user.agent" values="ie6" />
  <extend-property name="user.agent" values="ie8" />
  <extend-property name="user.agent" values="gecko1_8" />
  <extend-property name="user.agent" values="safari" />
  <extend-property name="user.agent" values="opera" />
  <extend-property name="user.agent" values="ie9" fallback-value="ie8" />
  <property-provider name="user.agent" generator="com.google.gwt.user.rebind.UserAgentPropertyGenerator"/>

Therefore gecko is not a valid value for user.agent in my case, and if I use gecko1_8 it compiles for Firefox fine.

因此,在我的情况下,gecko不是user.agent的有效值,如果我使用gecko1_8,它可以很好地编译Firefox。

#2


Works in GWT 1.6, your *.gwt.xml file :

适用于GWT 1.6,您的* .gwt.xml文件:

<module rename-to="moduleName">
      <!-- blah blah -->
      <set-property name="user.agent" value="ie6,gecko,gecko1_8" />
      <!-- generate perms for IE and firefox only -->
</module>

#3


for webkit based browsers like chrome, use "safari" as the user agent

对于像chrome这样的基于webkit的浏览器,使用“safari”作为用户代理

#4


In order to rapidly deploy any application, you'll need two targets; once for the engine your hosted mode deploys on {Firefox / Linux, Safari / Mac, IE6 / Win}, and one for your agile browser that lets you build css in real-time {Firefox + Firebug}.

为了快速部署任何应用程序,您需要两个目标;一次用于引擎,您的托管模式部署在{Firefox / Linux,Safari / Mac,IE6 / Win}上,一个用于您的敏捷浏览器,可以让您实时构建css {Firefox + Firebug}。

Linux: <set-property name="user.agent" value="gecko1_8,gecko"/>
Mac: <set-property name="user.agent" value="gecko1_8,safari"/>
...etc...

This is GWT >= 1.6 ONLY!

这只是GWT> = 1.6!

For older gwt projects, you must super-source the com/google/gwt/user/UserAgent.gwt.xml file... Put it in a source location that is included BEFORE your gwt-*.jar on the classpath. Basically, you can copy that file into a new one in the same package as the original, and edit the CDATA javascript block that returns the actual user.agent value. Play with this all you like, but don't go getting too crazy with their user.agent property, as it WILL be changing for ie8 in a future build.

对于较旧的gwt项目,您必须超级com / google / gwt / user / UserAgent.gwt.xml文件...将其放在包含在类路径上的gwt - * .jar之前的源位置。基本上,您可以将该文件复制到与原始文件相同的包中的新文件中,并编辑返回实际user.agent值的CDATA javascript块。玩这个你喜欢的,但不要对他们的user.agent属性过于疯狂,因为它将在未来版本中改变ie8。

To target ie browsers, make up your own ie.version property, and tweak a copy of the property-provider in UserAgent.gwt.xml to target different versions of ie. Just make sure that when you use the custom property for deferred binding you do:

要定位ie浏览器,请构建自己的ie.version属性,并在UserAgent.gwt.xml中调整属性提供程序的副本以定位不同版本的ie。只需确保在使用自定义属性进行延迟绑定时,您可以:

<all>
  <when-property-is name="user.agent" value="ie6"/>
  <any>
    <when-property-is name="ie.version" value="ie7"/>
    <when-property-is name="ie.version" value="ie8"/>
  </any>
</all>

Or you'll get ie7 + gecko/safari builds and other silly junk that will never be used.

或者你将获得ie7 + gecko / safari构建和其他永远不会被使用的愚蠢垃圾。

Note: Any code in a property-provider is loaded in the .nocache.js, and can be useful to preload images / css whilst the .cache.js payload is being downloaded.
Just add var __cached = new Image('Url To Compiled Image / Whatever you want to load');

注意:属性提供程序中的任何代码都加载到.nocache.js中,对于在下载.cache.js有效内容时预加载images / css非常有用。只需添加var __cached = new Image('Url To Compiled Image / Whatever you to loading');

#5


Not yet. The idea is that you develop rapidly to one browser and then compile once to deploy (i.e., do final testing) for all browsers, with GWT handling the browser differences. Don't forget that at deploy time GWT will optimize the downloads per browser so that in the end it doesn't matter how many user agents you chose.

还没。这个想法是你快速开发到一个浏览器然后编译一次以便为所有浏览器进行部署(即,做最终测试),GWT处理浏览器差异。不要忘记,在部署时,GWT将优化每个浏览器的下载量,以便最终与您选择的用户代理数量无关。

#1


I've had a similar error message, when setting the user.agent value to gecko in GWT2.4. So I looked around and found where the gwt code defines the possible values.

在GWT2.4中将user.agent值设置为gecko时,我遇到了类似的错误消息。所以我环顾四周,发现gwt代码定义了可能的值。

If you look in the gwt-user.jar at com.google.gwt.user.UserAgent.gwt.xml you can see the possible values for the version of GWT you are using.

如果您查看com.google.gwt.user.UserAgent.gwt.xml中的gwt-user.jar,您可以看到您正在使用的GWT版本的可能值。

For GWT2.4, this is what i found:

对于GWT2.4,这是我发现的:

<!-- Browser-sensitive code should use the 'user.agent' property -->
  <define-property name="user.agent" values="ie6" />
  <extend-property name="user.agent" values="ie8" />
  <extend-property name="user.agent" values="gecko1_8" />
  <extend-property name="user.agent" values="safari" />
  <extend-property name="user.agent" values="opera" />
  <extend-property name="user.agent" values="ie9" fallback-value="ie8" />
  <property-provider name="user.agent" generator="com.google.gwt.user.rebind.UserAgentPropertyGenerator"/>

Therefore gecko is not a valid value for user.agent in my case, and if I use gecko1_8 it compiles for Firefox fine.

因此,在我的情况下,gecko不是user.agent的有效值,如果我使用gecko1_8,它可以很好地编译Firefox。

#2


Works in GWT 1.6, your *.gwt.xml file :

适用于GWT 1.6,您的* .gwt.xml文件:

<module rename-to="moduleName">
      <!-- blah blah -->
      <set-property name="user.agent" value="ie6,gecko,gecko1_8" />
      <!-- generate perms for IE and firefox only -->
</module>

#3


for webkit based browsers like chrome, use "safari" as the user agent

对于像chrome这样的基于webkit的浏览器,使用“safari”作为用户代理

#4


In order to rapidly deploy any application, you'll need two targets; once for the engine your hosted mode deploys on {Firefox / Linux, Safari / Mac, IE6 / Win}, and one for your agile browser that lets you build css in real-time {Firefox + Firebug}.

为了快速部署任何应用程序,您需要两个目标;一次用于引擎,您的托管模式部署在{Firefox / Linux,Safari / Mac,IE6 / Win}上,一个用于您的敏捷浏览器,可以让您实时构建css {Firefox + Firebug}。

Linux: <set-property name="user.agent" value="gecko1_8,gecko"/>
Mac: <set-property name="user.agent" value="gecko1_8,safari"/>
...etc...

This is GWT >= 1.6 ONLY!

这只是GWT> = 1.6!

For older gwt projects, you must super-source the com/google/gwt/user/UserAgent.gwt.xml file... Put it in a source location that is included BEFORE your gwt-*.jar on the classpath. Basically, you can copy that file into a new one in the same package as the original, and edit the CDATA javascript block that returns the actual user.agent value. Play with this all you like, but don't go getting too crazy with their user.agent property, as it WILL be changing for ie8 in a future build.

对于较旧的gwt项目,您必须超级com / google / gwt / user / UserAgent.gwt.xml文件...将其放在包含在类路径上的gwt - * .jar之前的源位置。基本上,您可以将该文件复制到与原始文件相同的包中的新文件中,并编辑返回实际user.agent值的CDATA javascript块。玩这个你喜欢的,但不要对他们的user.agent属性过于疯狂,因为它将在未来版本中改变ie8。

To target ie browsers, make up your own ie.version property, and tweak a copy of the property-provider in UserAgent.gwt.xml to target different versions of ie. Just make sure that when you use the custom property for deferred binding you do:

要定位ie浏览器,请构建自己的ie.version属性,并在UserAgent.gwt.xml中调整属性提供程序的副本以定位不同版本的ie。只需确保在使用自定义属性进行延迟绑定时,您可以:

<all>
  <when-property-is name="user.agent" value="ie6"/>
  <any>
    <when-property-is name="ie.version" value="ie7"/>
    <when-property-is name="ie.version" value="ie8"/>
  </any>
</all>

Or you'll get ie7 + gecko/safari builds and other silly junk that will never be used.

或者你将获得ie7 + gecko / safari构建和其他永远不会被使用的愚蠢垃圾。

Note: Any code in a property-provider is loaded in the .nocache.js, and can be useful to preload images / css whilst the .cache.js payload is being downloaded.
Just add var __cached = new Image('Url To Compiled Image / Whatever you want to load');

注意:属性提供程序中的任何代码都加载到.nocache.js中,对于在下载.cache.js有效内容时预加载images / css非常有用。只需添加var __cached = new Image('Url To Compiled Image / Whatever you to loading');

#5


Not yet. The idea is that you develop rapidly to one browser and then compile once to deploy (i.e., do final testing) for all browsers, with GWT handling the browser differences. Don't forget that at deploy time GWT will optimize the downloads per browser so that in the end it doesn't matter how many user agents you chose.

还没。这个想法是你快速开发到一个浏览器然后编译一次以便为所有浏览器进行部署(即,做最终测试),GWT处理浏览器差异。不要忘记,在部署时,GWT将优化每个浏览器的下载量,以便最终与您选择的用户代理数量无关。