Reputation: 16399
Let's say I create an HTMLPanel
with some HTML like:
<p>
Blah blah <span id='1'>more html... </span>
</p>
Now I want to attach an event handler to the span. I want to see it as an InlineHTML
GWT widget. I tried:
HTMLPanel html = new HTMLPanel(stringOfHTML);
parentWidget.add(html);
String id = "1";
Element span = html.getElementById(id);
InlineHTML wid = InlineHTML.wrap(span); // -- error here
html.addAndReplaceElement(wid, id);
The second-to-last line dies with the AssertionError: A widget that has an existing parent widget may not be added to the detach list.
Is there a way to wrap sub elements in a HTMLPanel
?
This is GWT 2.4.
Note
After a few comments and answers I realized that I forgot to mention: usually UiBinder
is the answer here, but I'm not using it because the input is html text created in another context by non-programmers.
Upvotes: 3
Views: 4898
Reputation: 2460
Convert your <span>
into an InlineLabel inside your UiBinder template and attach anything you want to it :).
Upvotes: 0
Reputation: 9910
No, not really. You getting this exception because <span>
element is already a part of some widget. wrap
methods can be used only to create widgets on top of elements which are not part of some other widget. If you want to handle clicks on this span, you can add dom handler to the HTMLPanel
, and then detect which element was clicked.
Upvotes: 2