Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate UUID with GWT

Tags:

uuid

gwt

Is there any way to generate UUID with GWT?

like image 377
cupakob Avatar asked Sep 21 '10 10:09

cupakob


1 Answers

You can generate an UUID in GWT by reusing a Javascript UUID implementation an wrapping it using JSNI:

public native static String uuid() /*-{
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
            function(c) {
                var r = Math.random() * 16 | 0, v = c == 'x' ? r
                        : (r & 0x3 | 0x8);
                return v.toString(16);
            });
}-*/;

If you want just an unique ID (not an UUID) to use in your GWT elements, use:

String id = DOM.createUniqueId();
like image 67
Italo Borssatto Avatar answered Sep 22 '22 13:09

Italo Borssatto