In a gwt project I have a CellTree with custom cells. For easier testing I would like to add IDs for each of the cells. I know I can make it like this :
@Override
public void render(Context context,TreeElement value, SafeHtmlBuilder sb) {
if (value == null) {return;}
sb.appendHtmlConstant("<div id=\""+value.getID()+"\">" +
value.getName()) + "</div>";
}
But I would like to use something similar to EnsureDebugID() so I don't have to burn the IDs in the code. Is there a way to do that?
type 1 into the cell which is adjacent to the first data you want to add ID number. 2. Then in the cell below it, type this formula =IF(B1=B2,A1,A1+1), press Enter key to get the first result, drag fill handle down until last data showing up.
The simplest way to generate identifiers is by a serial number. A steadily increasing number that is assigned to whatever you need to identify next. This is the approached used in most internal databases as well as some commonly encountered public identifiers.
I would do something between the two of the aforementioned approaches. You should definitely add a prefix to be sure you can easily identify the cells during testing, and you should also take the createUniqueId()
approach rather than generating your own UUIDs which can be more troublesome.
@Override
public void render(Context context, TreeElement value, SafeHtmlBuilder sb) {
if (value == null) {return;}
String id = Document.get().createUniqueId();
sb.appendHtmlConstant("<div id=\"cell_"+id+"\">" +
value.getName()) + "</div>";
}
You can use
Document.get().createUniqueId();
Here the description:
/**
* Creates an identifier guaranteed to be unique within this document.
*
* This is useful for allocating element id's.
*
* @return a unique identifier
*/
public final native String createUniqueId() /*-{
// In order to force uid's to be document-unique across multiple modules,
// we hang a counter from the document.
if (!this.gwt_uid) {
this.gwt_uid = 1;
}
return "gwt-uid-" + this.gwt_uid++;
}-*/;
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