Use a custom gwt component created with uiBinder in another uiBinder?

4.9k views Asked by At

I have created a custom widget with uiBinder that I want to include in another uiBinder layout.

I tried:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:my="urn:import:net.sti.learning.client.view">
    <ui:style>

    </ui:style>
    <g:HTMLPanel>
        <g:VerticalPanel width="800px">
            <my:PostView ui:field="postView"/>
        </g:VerticalPanel>
    </g:HTMLPanel>
</ui:UiBinder>

But the gwt designer complains and says:

[ERROR] Failed to create an instance of 'net.sti.learning.client.view.PostView' via deferred binding

EDIT:

here is the PostWidget.ui.xml:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui">
    <ui:style>

    </ui:style>
    <g:HTMLPanel width="600px" height="">
        <g:DecoratorPanel width="600px" height="">
            <g:VerticalPanel width="600px" height="">
                <g:HorizontalPanel width="600px" height="30px" verticalAlignment="ALIGN_MIDDLE">
                    <g:Label text="This is the post title" width="500px" height="30px" horizontalAlignment="ALIGN_LEFT" ui:field="postTitle"/>
                    <g:SimplePanel width="100px" height="30px" styleName="dateDiv">
                        <g:DateLabel width="100%" height="100%" horizontalAlignment="ALIGN_RIGHT" ui:field="postDate"/>
                    </g:SimplePanel>
                </g:HorizontalPanel>
                <g:SimplePanel width="600px" height="auto" styleName="postContent">
                    <g:HTML wordWrap="true" width="100%" height="100%" ui:field="postContent">Lorem ipsum dolor sit amet, cursus sapien in vivamus, et ligula luctus eu ut et vitae, mauris ultrices nec. Dictum volutpat mauris sit mattis vestibulum tristique, suspendisse pede aliquam dapibus etiam, occaecati et fusce tempor sit, vel libero adipiscing sed est, non mus. Varius ullamcorper orci ornare parturient ab, risus molestie est magna, felis tempus tortor justo nunc ullamcorper nam. Nulla in vel nunc eu libero, duis nibh fermentum gravida, nullam magna mauris, sem accumsan. Amet sollicitudin mi lectus, lectus malesuada et porta sit, per ipsum blandit, lacinia diam at donec. Sem eget lectus aliquam ac, erat non lectus id illum, tristique et elementum et potenti sed nostra, amet eget. Lectus tincidunt massa dolor, erat nonummy mauris pulvinar aenean mauris.</g:HTML>
                </g:SimplePanel>
                <g:SimplePanel width="600px" height="30px">
                    <g:InlineLabel text="Author" width="100%" height="100%" horizontalAlignment="ALIGN_CENTER" ui:field="postAuthor"/>
                </g:SimplePanel>
            </g:VerticalPanel>
        </g:DecoratorPanel>
    </g:HTMLPanel>
</ui:UiBinder> 

and its associated java file:

package net.sti.learning.client.view;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.DateLabel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.InlineLabel;

public class PostWidget extends Composite {

    private static PostWidgetUiBinder uiBinder = GWT
            .create(PostWidgetUiBinder.class);
    @UiField Label postTitle;
    @UiField DateLabel postDate;
    @UiField HTML postContent;
    @UiField InlineLabel postAuthor;

    interface PostWidgetUiBinder extends UiBinder<Widget, PostWidget> {
    }

    public PostWidget() {
        initWidget(uiBinder.createAndBindUi(this));
    }

    public void setData(String title, Date pubDate, String content, String author){
        this.postTitle.setText(title);
        this.postDate.setValue(pubDate);
        SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
        safeHtmlBuilder.appendEscapedLines(content);
        SafeHtml safeContent = safeHtmlBuilder.toSafeHtml();
        this.postContent.setHTML(safeContent);
        this.postAuthor.setText(author);
    }

}

Anyone has ever done that before?

Thanks!

0

There are 0 answers