Generate UUID with GWT

前端 未结 2 1092
不思量自难忘°
不思量自难忘° 2021-02-13 05:01

Is there any way to generate UUID with GWT?

相关标签:
2条回答
  • 2021-02-13 05:26

    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();
    
    0 讨论(0)
  • 2021-02-13 05:31

    According to this page:

    http://2ality.blogspot.com/2009/01/uuids-for-gwt.html

    This UUID generator works with GWT:

    http://www.pst.ifi.lmu.de/%7Erauschma/download/UUID.java

    0 讨论(0)
提交回复
热议问题