My GWT application creates text areas, each of which must have an ID in order to be useful to a third-party JavaScript library. I know how to assign an ID to a GWT widget; I'm after a good way of generating those unique ID's.
For GWT, take a look at HTMLPanel.createUniqueId
String id = HTMLPanel.createUniqueId();
I believe this would be what you need for unique identifiers ( using a timestamp and the 'widget-' namespace ).
'widget-' + (new Date).valueOf()
Java has a built-in class for unique ID creation: http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html
Another common way is by using a timestamp, i.e. System.currentTimeMillis()
Javascript:
var idIndex = 0;
function getNewId() {
return "textGWT"+(idIndex++);
}
Java:
class IdMaker {
private static int idIndex = 0;
public static String generate() {
return "textGWT"+(idIndex++);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With