Is it possible to create a TextBox using GWT.create
, not the constructor, and wrap an existing HTML element?
I tried:
TextBox text=GWT.create(TextBox.class)
text.setElement(DOM.createInput()) (2)
The above fails on line (2) with "cannot set element twice ..."
I need this in order to use GwtMockito and test a component that needs to create a TextBox.
Thank you!
It seems you'd have to resort to using some sort of factory:
This will get injected into your view and you'll use the factory to wrap the existing element in a
TextBox
. The default implementation will, of course, just useTextBox#wrap(Element)
, as suggested by Baz. For the purposes of your tests, you'll use an implementation that returns a Mockito mock.Not the prettiest solution, but given the circumstances, I can't think of a "cleaner" one.