GWT: How do I assign an ID to editable table cells in a CellTable?
-
04-03-2021 - |
Question
I'm using GWT 2.4. I'm constructing a CellTable with some editable table cells. My question is, when the cells are rendered, how do I force them to be rendered with a "name" and/or "id" attribute defined within the input tag? Right now, the code I have for rendering the cell is ...
class EditableTableCell extends TextInputCell {
private final List<Node> colData;
public EditableTableCell(final List<Node> colData) {
super();
this.colData = colData;
}
@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
final Integer index = context.getIndex();
final Node childNode = colData.get(index);
if (childNode.getAttributes() != null &&
childNode.getAttributes().get("edit") != null &&
childNode.getAttributes().get("edit").getValue() != null &&
childNode.getAttributes().get("edit").getValue().equalsIgnoreCase("yes")) {
super.render(context,value,sb);
} else {
sb.appendEscaped(value);
} // if
}
}
If the cell is editable, the resulting html looks like ...
<td class="GCSPOWVPD GCSPOWVBE GCSPOWVCE GCSPOWVME">
<div style="outline:none;" tabindex="0">
<input type="text" value="\n\t\t\tABC\n\t\t" tabindex="-1"></input>
</div>
</td>
Although "type", "value", and "tabindex" get defined, no "name" or "id". Trying to figure out how to do this. Thanks, - Dave
Solution
Where you're doing super.render(...)
, I would instead render that HTML myself, and stick in a name and id value for the input
element manually. I answered a similar question on this concept here. Idea is slightly different, but implementation would be the same.