GWT:在客户端使用DateTimeFormat,在服务器上使用SimpleDateFormat [英] GWT: use DateTimeFormat on client and SimpleDateFormat on server

查看:289
本文介绍了GWT:在客户端使用DateTimeFormat,在服务器上使用SimpleDateFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数必须在客户端和服务器上以相同的方式工作,并且它格式化日期。

  if(GWT .isClient())
{
//使用DateTimeFormat
} else {
//使用SimpleDateFormat
}

GWT抱怨:没有源代码可用于SimpleDateFormat类型。错误不是致命的(至少在开发模式下),但是很烦人,而且没办法压制它。
http:// groups上找到类似的问题。 google.com/group/google-web-toolkit/browse_thread/thread/981247fca161c287 。在那里,他们建议:

lockquote

你可以提供一个虚拟超级实现
SimpleDateTimeFormat,以便它能够被编译。


我试过了。现在Eclipse抱怨:

lockquote

java.text
声明的包java.text与预期的包foo不匹配。 jre.java.textSimpleDateFormat.java


解决方案

您必须告诉Eclipse不要编译你的超级源代码的Java文件。如果您使用的是Maven,只需将其移至src / main / resources;否则,从Eclipse的构建路径中排除您的'jre'



...这就是说,我宁愿超级源类使用SimpleDateFormat / DateTimeFormat,和/或将它移动到您需要超级源的助手类。


I have a function that must work the same way on both client and server and it formats dates.

if (GWT.isClient())
{
  // Use DateTimeFormat
} else {
  // Use SimpleDateFormat
}

GWT complains: No source code is available for type SimpleDateFormat. The error is not fatal (at least in dev mode), but annoying and no way to suppress it. Found a similar question on http://groups.google.com/group/google-web-toolkit/browse_thread/thread/981247fca161c287 . There they suggest:

You can provide a dummy supersource implementation of SimpleDateTimeFormat so that it would compile.

I tried. Now Eclipse complains:

java.text The declared package "java.text" does not match the expected package "foo.jre.java.text" SimpleDateFormat.java

解决方案

You have to tell Eclipse not to compile your super-source'd Java file. If you're using Maven, it's simply a matter of moving it to src/main/resources; otherwise, exclude your 'jre' package from Eclipse's build path.

...that being said, I'd rather super-source the class the uses the SimpleDateFormat/DateTimeFormat, and/or move that to a helper class that you'd super-source.

这篇关于GWT:在客户端使用DateTimeFormat,在服务器上使用SimpleDateFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆