GWT: How can I add UiBinder xml layout to my Widget?

孤街浪徒 提交于 2019-12-25 11:48:13

问题


I have a button which is a direct descendant of GWT PushButton. I want to add UiBInder xml layout to my button to simplify its design. I have created MyButton.ui.xml and I have the following contents of MyButton:

class MyButton extends PushButton 
{

interface UI extends UiBinder<Widget, MyButton>
{
}

private static final UI ui = GWT.create(UI.class);

@UiConstructor
public MyButton() {
        super();
        ui.createAndBindUi(this);
}

(...)

}

The problem is that my button is not rendered. GWT creates some div and places input element inside, but the layout I have created inside my uibinder xml file is not applied. Where I went wrong?


回答1:


I am not really sure, but, may be it's because you don't implement the asWidget() method:

@Override
public Widget asWidget() {
    return widget;
}

where widget is declared:

private final Widget widget;

and initialized in you constructor as:

widget = ui.createAndBindUi(this);

Hope this helps




回答2:


To directly respond to your question, the xml have to look like (with the necessary adjustments):

<ui:image field='downButton'/>
<g:PushButton ui:field='pushButton' enabled='true'>
  <g:upFace>
    <b>click me</b>
  </gwt:upFace>
  <g:upHoveringFace>
    <b>Click ME!</b>
  </gwt:upHoveringFace>

  <g:downFace image='{downButton}'/>
  <g:downHoveringFace image='{downButton}'/>
</g:PushButton>

See http://google-web-toolkit.googlecode.com/svn/javadoc/2.5/com/google/gwt/user/client/ui/CustomButton.html for the syntax. Then into your MyButton you should use a method marked with @UiFactory in order to pickup the proper instance to supply the UiBinder GWT.create().

@UiFactory
DialogBox thatsJustMe() {
  // UiBinder will call this to get a PushButton instance.
  return this;
}

Anyway, you cannot change the structure of the widget. You are bound to its definition.



来源:https://stackoverflow.com/questions/15548465/gwt-how-can-i-add-uibinder-xml-layout-to-my-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!