How to create documentFragment in GWT?

Creating a document fragment using simple Javascript is very simple: var docFragment = document.createDocumentFragment(); .
However, in GWT, this does not seem to be accessible, although there is a DocumentFragment interface in the com.google.gwt.xml.client package, which does not seem to be applicable. Does anyone know a way using the above interface or creating a class using a simple JSNI method that creates documentFragment?

Thanks.

+4
source share
2 answers

Creating a JSNI method that returns a DocumentFragment is simple, simple. You just return document.createDocumentFragment(); :). The JSNI method should either return a JavaScriptObject or some other type that you know will work (e.g. Node - I'm not sure what you are going to do with this, but JSOs work that way - you can cast<T>() any subclass of JavaScriptObject to any other JavaScriptObject ).

+2
source

This specific issue is being addressed (with a workaround similar to Climer's suggestion) in " Problem 2955: Unable to create document fragment object for dom " on the GWT tracker.

You can also contribute to this ticket and β€œlight up” the problem to show your interest in adding it to the GWT framework.

+2
source

All Articles