James-Jesse Drinkard
James-Jesse Drinkard

Reputation: 15703

How to nest a composite widget into the main ui.xml file using uiBinder?

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?

Upvotes: 2

Views: 2658

Answers (2)

James-Jesse Drinkard
James-Jesse Drinkard

Reputation: 15703

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:

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
 xmlns:g="urn:import:com.google.gwt.user.client.ui"
 xmlns:u="urn:com.abc.client.view">

However, the last line should have had the word import in it:

xmlns:u="urn:import.com.abc.client.view">

This is where I found the answer.

I hope this helps someone, this cost me a lot of time!

Upvotes: 5

Strelok
Strelok

Reputation: 51441

You didn't show more UI binder markup around where you are inserting the MyClass widget, but if you have your widget inside some raw HTML you need to have all this HTML in an HTMLPanel.

Upvotes: 1

Related Questions