Make a generic interface for the methods you need and a factory; on
the client side set the factory to create a DateTimeFormat version of
the interface, and on the server a SimpleDateFormat version, in the
initialization code for the client (onModuleLoad) and server
(HttpServlet).

On May 25, 6:16 am, Jogi <[email protected]> wrote:
> Hi,
>
> I have a little problem and I hope someone can help me to solve it. I
> have a class which used on client and server side, mainly to parse
> Strings into Dates...
>
> So I use on client side the com.google.gwt.i18n.client.DateTimeFormat
> and on server side the java.text.SimpleDateFormat. The code of the
> class got more and more and I don't want to have the same class (the
> only different is really this one formatting part) on client and
> server side... Is there a way to do a switch like:
>
> Date parsed = null;
> if (GWT.isScript()) {
> com.google.gwt.i18n.client.DateTimeFormat formatter =
> com.google.gwt.i18n.client.DateTimeFormat.getFormat(this.getFormat());
> parsed = formatter.parse(value);} else {
>
> java.text.SimpleDateFormat formatter = new
> java.text.SimpleDateFormat(this.getFormat());
> parsed = formatter.parse(value);
>
> }
>
> This way does not work, cause the GWT Compiler does not see that it
> will always be true and skip the second part... on server side this
> would work fine (I guess) cause isScript would be false, so the
> annoying GWT.create() error would not be raised... but is there some
> way to get such a switch?
>
> Thanks!

-- 
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