开发者

Facing a problem with GWT Data Serialization

开发者 https://www.devze.com 2023-02-05 05:03 出处:网络
This is similar to the question:GWT Data Serialization I am using Date Object @ my client, Here is what I tried,

This is similar to the question: GWT Data Serialization

I am using Date Object @ my client,

Here is what I tried, I created a Date Object, showed its toString() in a Label and passed it to server via Rpc whose return value is the same Date's toString()

value passed:

Date value = new Date(2011, 0, 19);

Output @ Hosted/Development mode : (http://127.0.0.1:8888/MyApplication.html?gwt.codesvr=127.0.0.1:9997)

Client Reads: Thu Jan 19 00:00开发者_运维技巧:00 IST 3911 Server reads:Thu Jan 19 00:00:00 IST 3911

Output @ Production mode (after GWT compile) : (http://127.0.0.1:8888/MyApplication.html)

Client Reads: Thu Jan 19 00:00:00 GMT+530 3911 Server reads:Thu Jan 19 00:00:00 IST 3911

Output @ Deploying in Jboss running in the same Machine :

Client Reads: Thu Jan 19 00:00:00 GMT+530 3911 Server reads:Wed Jan 18 18:30:00 GMT 3911

What's mind boggling is that its the same machine and hence the locale, etc should ideally be the same, still @ hosted mode I see client sends IST server receiving IST, @production I see client sends GMT server receives IST and @Jboss server deploy I see client sends GMT and server receives GMT with one Day less !!

The fact that the server recieves one day less is very seriously affecting my application business logic, basically I am using iBatis thats populating my pojos from database and sending it to client and at client I am using GXT which is showing me a UI for date selection.

Using String for date is not suitable for me since its a major change in application core pojos, all database select and insert queries just because my client library does not handle Dates well.

Does anyone have a alternative to this ?


You can try to use DateTimeFormat to build something that is unambiguous among machines despite locales. Format like 'yyyy-MM-dd HH:mm:ss ZZZZ' instead of using toString()

Date today = new Date();
DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss ZZZZ");
GWT.log(fmt.format(today));
0

精彩评论

暂无评论...
验证码 换一张
取 消