Wednesday, November 21, 2012

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

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


--
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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment