replace-with and when-property-is . . using it based on browser / user.agent value?

151 views
Skip to first unread message

King_V

unread,
Nov 21, 2012, 5:28:54 PM11/21/12
to google-we...@googlegroups.com
All,

I've seen a few examples where there is talk of substituting a class based on which browser is involved.

So, I want to have one version of a class for Firefox, and one for everything else.

I've tried the following, taken from examples I've found online:

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <inherits name="com.sencha.gxt.theme.base.Base" />
   
    <replace-with class="com.joev.tests.client.MultiplierAdjustmentFirefox">
        <when-type-is class="com.joev.tests.client.MultiplierAdjustment" />
        <when-property-is name="user.agent" value="firefox" />
    </replace-with>
</module>

However, it doesn't seem to work.  I'm pretty sure the value isn't just "firefox" but I don't know what to put in there.  Or it may be the static method doing the instantiation of the MultiplierAdjustment class.

Basically I want any version of Firefox to use the MultiplierAdjustmentFirefox class, and other browsers (so far we're only supporting Chrome and IE) to use the MultiplierAdjustment class.

Here's the basic code I used to test it:
GenericOutput.java (yeah, I'm not very creative with my names):
public class GenericOutput implements EntryPoint {

  @Override
  public void onModuleLoad() {
    RootPanel.get().add(new Label(GenericStuff.getClassNameForInstance() + " has a value of: " + GenericStuff.getMultiplierValue()));
  }
}

GenericStuff.java:
public class GenericStuff {

  private static MultiplierAdjustment instance;

  private static MultiplierAdjustment getInstance() {
    if(instance == null) {
      instance = new MultiplierAdjustment();
    }
    return instance;
  }

  public static String getClassNameForInstance() {
    return getInstance().getClass().getName();
  }

  public static double getMultiplierValue() {
    return getInstance().getMultiplier();
  }
}

MultiplierAdjustment.java:
public class MultiplierAdjustment {
  public double getMultiplier() {
    return 1.3;
  }
}

MultiplierAdjustmentFirefox.java:
public class MultiplierAdjustmentFirefox {
  public double getMultiplier() {
    return 1.07;
  }
}

So, why am I getting output saying:  
com.joev.tests.client.MultiplierAdjustment has a value of: 1.3

How do I get this to work correctly?

Thanks in advance


Alberto Mancini

unread,
Nov 21, 2012, 5:42:19 PM11/21/12
to google-we...@googlegroups.com
Hi,
probably RichText.gwt.xml in com.google.gwt.user may help you,
I think the following is the relevant part:

 <!-- Mozilla-specific implementation -->
  <replace-with
    class="com.google.gwt.user.client.ui.impl.RichTextAreaImplMozilla">
    <when-type-is
      class="com.google.gwt.user.client.ui.impl.RichTextAreaImpl" />
    <when-property-is name="user.agent" value="gecko1_8" />
</replace-with>


Ciao,
   Alberto.





--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/gaFuEob_9xgJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Jens

unread,
Nov 21, 2012, 6:22:36 PM11/21/12
to google-we...@googlegroups.com
User agent values can be found in UserAgent.gwt.xml in gwt-user.jar (https://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/useragent/UserAgent.gwt.xml)

Firefox is "gecko1_8" (the name of the rendering engine of Firefox).

Also, you must use GWT.create(MultiplierAdjustment.class) instead of new MultiplierAdjustment(). Generators and deferred binding are only triggered when using GWT.create().

-- J.

King_V

unread,
Nov 26, 2012, 9:59:20 AM11/26/12
to google-we...@googlegroups.com
Thanks - that did the trick!


Reply all
Reply to author
Forward
0 new messages