Generate UUID with GWT

匆匆过客 提交于 2019-12-04 17:50:46

问题


Is there any way to generate UUID with GWT?


回答1:


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




回答2:


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();


来源:https://stackoverflow.com/questions/3759590/generate-uuid-with-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!