grid, header and events

157 views
Skip to first unread message

Dennis Haupt

unread,
Aug 16, 2012, 8:56:15 AM8/16/12
to google-we...@googlegroups.com
i'm trying to add widgets into a flextables header. the header itself required me to add native th / tr elements and add my widgets there:
if (model.header().totalHeaderRowCount() > 0) {
final Element head = DOM.createElement("thead");
for (final int headerRowIndex : CollectionFunctions.range(model.header().totalHeaderRowCount())) {
final Element headerRow = DOM.createElement("tr");
DOM.appendChild(head, headerRow);
for (int col = 0; col < totalColumnCount; col++) {
final HeaderCell cell = model.header().cellAt(headerRowIndex, col);
final Widget widget = createWidget(cell.asTableCellContent());
final Element th = DOM.createTH();
DOM.setElementAttribute(th, "colSpan", String.valueOf(cell.colSpan()));
col += cell.colSpan() - 1;
DOM.appendChild(th, widget.getElement());//<-- important line
DOM.appendChild(headerRow, th);
}
DOM.insertChild(grid.getElement(), head, 0);
}
}

everything works, except for events. they seem to get lost somewhere and don't reach the listeners anymore.
how can i fix it?

Jens

unread,
Aug 16, 2012, 10:45:31 AM8/16/12
to google-we...@googlegroups.com, d.ha...@googlemail.com
Take a look at ComplexPanel.add(Widget, Element) to see what GWT does when adding a widget to another. Technically the method Widget.onAttach() must be called to activate event handlers and Widget.onDetach() to clean them up. In GWT these methods are called in Widget.setParent() which is called during the adoption phase via Panel.adopt() which in turn is called by ComplexPanel.add() to finalize the widget attachment.

You would need to call onAttach/onDetach yourself but these methods are all non-public for a good reason, so you can only call them when writing a custom widget. In onAttach/onDetach you can see what GWT does to activate/cleanup event handlers at DOM level. 

I think from outside your widget you cant activate/cleanup event handlers for your widget (prevents possible memory leaks). I would create a custom header widget to fix the problem. The custom widget can then wrap the child widget with thead/tr/th as needed.

-- J.
Reply all
Reply to author
Forward
0 new messages