Nice.... thanks for pointing out

-- Ed

On Apr 11, 8:06 am, Vitali Lovich <[email protected]> wrote:
> Sweet - that's a clever approach.
>
> On Sat, Apr 11, 2009 at 1:26 AM, Adam T <[email protected]> wrote:
>
> > Vitali, you'd just create your own property with two values:
> > Generically:
>
> > 1. Define the properties:
> >    <define-property name="prod.status" values="production,test"/>
>
> > 2. Define a property provider; for example as simple one as folows:
> >    <property-provider name="prod.status">
> >    <![CDATA[
> >       try{
> >          var prodStatus = __gwt_getMetaProperty("prod.status");
> >          if (prodStatus==null){
> >             prodStatus = "production";
> >          }
> >          return prodStatus;
> >       } catch (e) {
> >          return "test";
> >       }
> >    ]]>
> >    </property-provider>
>
> > 3.  Stick the meta tag use for the property provider in your html
> > file's head section
> >        <meta name='gwt:property' content='prod.status=test'>
>
> > Note: For a flag such as a production/test switch I guess you're only
> > ever interested in one set of permutations or the other, so you could
> > ignore steps 2 and 3 and just use a set-property in your xml file to
> > restrict to one value:
>
> > <set-property name="prod.stats" values="test">
>
> > Then you get the benefit of switching, plus avoid the double
> > compilation time this approach brings if you allow it to compile for
> > both values of prod.status.
>
> > 4.  Then you can use your new property as a standard one, for example
> > to replace files during compilation
>
> >  <replace-with class="foo.FooMockImpl">
> >     <when-type-is class="foo.FooProdImpl" />
> >    <when-property-is name="prod.status" value="test" />
> >  </replace-with>
>
> > 5.  Optionally if you're using the generic approach to switch
> > properties in the HTML file, you could add some error handling for the
> > property by defining an onPropertyErrorFn in your HTML head section:
> >        <meta name='gwt:onPropertyErrorFn'
> > content='handleWrongProdStatus'>
> >        <script>
> >           function handleWrongProdStatus(propName, allowedValues,
> > badValue){
> >              if (propName == "prod.status"){
> >                 window.alert("You are trying to use an incorrect
> > production status value: ."+badValue);
> >              }
> >           }
> >        </script>
>
> > //Adam
>
> > On 11 Apr, 06:51, Vitali Lovich <[email protected]> wrote:
> > > On Sat, Apr 11, 2009 at 12:50 AM, Vitali Lovich <[email protected]>
> > wrote:
> > > > Nope.  In fact, it's even more powerful because you can put in complex
> > > > conditionals.  Ideally, you wouldn't even need to files because you
> > could
> > > > just pick 1 class when in production, 1 class when in development, but
> > that
> > > > selection would still be in a single Foo.gwt.xml.
>
> > > Forgot to mention here that I said ideally because I don't know of any
> > way
> > > to do that currently (i.e. set an environment variable or something).  I
> > > only know how to do selection by user agent.  Am I wrong?  Are there more
> > > complex properties?
>
> > > > Also, you may find it helpful to use
>
> > > > <module rename-to="actual_module_name">
>
> > > > so that if you do use multiple module xml files, you don't have to
> > change
> > > > any other configuration files (i.e. servlet definitions etc).
>
> > > > On Fri, Apr 10, 2009 at 11:52 AM, Yves <[email protected]>
> > wrote:
>
> > > >> Hello
>
> > > >> Reading the documentation for the module xml files, i just realize
> > > >> that the tag <replace-with .../> allows for dependency injection.
>
> > > >> Suppose i need to use different class implementation depending on my
> > > >> environment (real class for production, mock for development ...). I
> > > >> just have to have two (or more) module xml like this
>
> > > >> For production use file FooProd.gwt.xml
>
> > > >> <module>
> > > >>  <replace-with class="foo.FooProdImpl">
> > > >>    <when-type-is class="foo.Foo" />
> > > >>  </replace-with>
> > > >>  ...
>
> > > >> For development use file FooDev.gwt.xml
>
> > > >> <module>
> > > >>  <replace-with class="foo.FooMockImpl">
> > > >>    <when-type-is class="foo.Foo" />
> > > >>  </replace-with>
> > > >>  ...
>
> > > >> Am i wrong?
>
> > > >> Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to