问题
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