Generate a unique ID string on client side.

463 views
Skip to first unread message

byhisdeeds

unread,
May 6, 2008, 10:32:04 PM5/6/08
to Google Web Toolkit
Can anyone point me in the best way to create a unqiue ID string in
GWT, on the client side. This should be a once only string that I will
use to communicate with a server. I don't want to have to ask a server
to genrate it and then use it.

I see that the Date classes don't seem to be implemented, so I'm not
sure what's the best thing to do.

John

Ian Petersen

unread,
May 6, 2008, 11:16:37 PM5/6/08
to Google-We...@googlegroups.com
On Tue, May 6, 2008 at 10:32 PM, byhisdeeds <byhis...@gmail.com> wrote:
> Can anyone point me in the best way to create a unqiue ID string in
> GWT, on the client side. This should be a once only string that I will
> use to communicate with a server. I don't want to have to ask a server
> to genrate it and then use it.

Dunno if it's the "best" way, but you could generate a bunch of random
bytes and format them into a UUID. There are some rules about
randomly-generated UUIDs--something about certain fields within the
UUID having certain values--but I think that information is probably
at the other end of a Google search.

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

Ravi M

unread,
May 7, 2008, 12:37:51 AM5/7/08
to Google Web Toolkit
If you're only looking for a unique ID string within the context of
one client and one session, you _could_ use an ID generator based on
System.currentTimeMillis() (which is emulated by GWT). Of course, if
you're going to be generating IDs at a rate of > 1 per millisecond,
you'd have to add some code to make sure that you generate different
IDs for the same millisecond.

If you need globally unique IDs, you might have to use a combination
of the above with a unique session ID that you'd get from the server.

Ravi

Carl Scott

unread,
May 7, 2008, 12:38:38 AM5/7/08
to Google Web Toolkit
The (deprecated) date class is indeed implemented, you just can't use
Calendar. And I would use that.

--
Carl Scott
Software Developer, Solertium Corporation
Reply all
Reply to author
Forward
0 new messages