3

I am trying to manipulate the DOM extensively from my Gwt code. In the process I discovered two groups of classes implementing a common base interface e.g..

interface DivBuilder  

class HtmlDivBuilder implements DivBuilder

class DOMDivBuilder implements DivBuilder 

for each and every Html tag there are two such sets of classes implemented

I am confused as to what is the purpose and use behind this.

Any pointers shall be helpful .

Gautam
  • 1,030
  • 13
  • 37

1 Answers1

2

The Html family builds a string that can later be used with innerHtml. It can be used server-side too.

The Dom family builds a DOM subtree.

The goal is you can have code that uses the builders and can be called with either concrete implementation depending on the use case. As an example, the cell table could use either strategy and the builders could stay the same.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • how to use the Html family of builders .. through Document ? – Gautam Nov 28 '14 at 11:42
  • 1
    Start with an `HtmlBuilderFactory` and end by calling `asSafeHtml()` on any `HtmlElementBuilderBase`. Similarly for `Dom*Builder`s, start with a `DomBuilderFactory` and end by calling `finish()`. In between, you can just use the `com.google.gwt.dom.builder.shared.*Builder` interfaces, independently of the underlying implementation. – Thomas Broyer Nov 28 '14 at 12:14
  • how is it different from Document class ? – Gautam Nov 29 '14 at 13:39
  • for future reference - http://www.gwtproject.org/javadoc/latest/com/google/gwt/dom/builder/shared/ElementBuilderFactory.html – Gautam Nov 29 '14 at 13:40