I have a task to add a composite widget into the main ui.xml file, but it’s not working for some reason. Here is my widget code:
public class MyClass extends Composite {
@UiTemplate("MyClass .ui.xml")
interface MyClassUiBinder extends UiBinder<Widget, MyClass > {
}
private static MyClassUiBinder uiBinder = GWT.create(MyClassUiBinder.class);
@UiField Label label;
public MyClass() {
initWidget(uiBinder.createAndBindUi(this));
} ...
Then in my main viewImpl.ui.xml class:
I declare the class package:
... xmlns:u="urn:com... client.view">
and then the widget itself:
<g:HTMLPanel ui:field="mainPanel" styleName="{style.mainPanel}">
<table align="center">
<tr>
<td align="center">
<u:MyClass/>
</td>
</tr>
I also tried setting up a ui:field declaration in the viewImpl class, but I got an error thrown at compile time:
ERROR] In @UiField myClass, template field and owner field types don’t match: com.google.gwt.dom.client.Element is not assignable to com… client.view.MyClass
When I took the @UiField declaration out of the viewImpl and the ui.xml it compiled, but the widget wasn’t displaying when the page loaded.
I created another composite widget class and tried to duplicate this with just a button widget.
Using firebug I see that the element has been added to the main ui.xml page, but it also is not displaying, so my binding isn’t totally complete somehow.
What am I missing here?
I found the problem, GWT was telling me that I didn’t do my declaration properly, but the error wasn’t as descriptive as I would have liked.
In the main.ui.xml file I used:
However, the last line should have had the word import in it:
This is where I found the answer.
I hope this helps someone, this cost me a lot of time!