I'm not sure, if I got your problem right - but I had a similar
problem and think this could help:
If we need different implementations on the client and serverside this
is the way we go:
* create an interface for all common functions. e.g. ICommonStuff
with function: doSmth()
* have a ServerImpl and a ClientImpl class that implement the
ICommonStuff interface
* build one Helper class that has a getter and setter for
ICommonStuff
* on startup at the client/serverside create the proper instance
that implements ICommonStuff and pass it to the setter of the Helper
class
* on the client-side the module entry point will be a good place
for this
public class Main implements EntryPoint {
public void onModuleLoad() {
Helper.setCommonStuff((ICommonStuff) GWT.create
(ClientImpl.class));
...
}
}
* on the server-side it depends on which framework you use, but
you simply set your server-impl:
Helper.setCommonStuff(new ServerImpl());
* whenever you need any common function you can now simply call:
Helper.getCommonStuff().doSmth()
instead of the helper you could also use some sort of DI - google for
GIN/JUICE
I really wished we could have some code-formatting in this forum...
On Sep 7, 5:18 pm, james turner <[email protected]> wrote:
> I'm wondering if there is a facility in the gwt compiler to perform a
> "replace-with" for classes that aren't gwt client side compliant.
>
> For example, I have 2 implementations of DateFormatterFactory. One
> implementation uses SimpleDateFormat, and the other uses
> DateTimeFormat. As such, when I construct an implementation, I have
> to know which side of the wire I'm on, because SimpleDateFormat won't
> compile in gwt and DateTimeFormat won't run in the JRE. Currently, I
> have to pass the factory in as a dependency through several layers of
> constructors, but it would be nice if I could simply write all of my
> code using SimpleDateFormat implementation, and then have the gwt
> compiler swap in the gwt client-side implementation at compile time.
>
> Honestly, it could be as simple as a find-replace precompiler step
> that replaces all occurrences of
> "myproject.server.SimpleDateFormatFactory" with
> "myproject.client.DateTimeFormatFactory". Another solution that could
> work, is if you could annotate/comment on a static block or method
> such that the gwt compiler would ignore it.
>
> the replace-with tag won't work, because it requires you to use
> GWT.create() which doesn't work on the server side. Also, checking to
> see if you're in hosted mode and if not calling "new SimpleDate..." or
> "Class.forName..." won't work because the gwt compiler will not
> compile a class with those statements.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---