UiBinder - HTMLPanel vs. div
Asked Answered
C

2

14

Is there some sort of penalty when I'm using a HTMLPanel instead of a plain div?

E.g.

<g:HTMLPanel>
  <div>
    /* Widgets, more HTML */
  </div>
</g:HTMLPanel>

in contrast to

<g:HTMLPanel>
  <g:HTMLPanel>
    /* Widgets, more HTML */
  </g:HTMLPanel>
</g:HTMLPanel>
Cladoceran answered 21/3, 2011 at 19:11 Comment(0)
S
9

Short answer:

When in doubt, look at the generated code (pass the -gen argument to the DevMode or Compiler)

Long answer:

There will be a runtime performance penalty using a widget over a simple DOM element, always. And even more when that DOM element is created by parsing an HTML snippet.

When UiBinder sees a widget as a child of HTMLPanel, it will generate a placeholder <span> with a generate unique ID and then use the HTMLPanel.addAndReplaceElement to replace that placeholder with a widget.

So the second snippet will generate (approx)

HTMLPanel root = new HTMLPanel("<span id='uuid'></span>");
HTMLPanel child = new HTMLPanel("/* Widgets, more HTML. */");
root.addAndReplaceElement(child, "uuid");
Stomatitis answered 21/3, 2011 at 23:14 Comment(0)
I
2

This isn't a performance penalty, but I think HTMLPanel is the only Widget that, within a UiBinder, can contain (as children) a mix of both Widget and HTML tags.

Irony answered 31/10, 2015 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.