3

I'm creating a composite uibinder widget with a Label and a TextBox.

The intented use is:

<x:XTextBox ui:field="fieldName" label="a caption" >
    The text to be put in the box.
</x:XTextBox>

I've found how to catch the label with a custom @UiConstructor constructor, I might add another parameter to the constructor, but I would like to know how to get the text from the xml, just like the GWT tag <g:Label>a caption</g:Label> does.

Any help is greatly appreciated.

4

3 回答 3

3

通过查看标签小部件源代码,我找到了一个可能的实现。

关键是复合小部件必须实现 HasText 接口。所以在声明和正文中:

public class XTextBox extends Composite implements HasText ...
...
@UiField TextBox textBox;
...
public void setText(String text) {
    textBox.setText(text);
}
public String getText() {
    return textBox.getText();
}
...
于 2010-05-17T15:53:11.277 回答
0

韩是对的;HasText 是您需要实现的。我发现方便的一件事是如果您知道 Google 小部件也可以执行您想做的事情,请浏览源代码。例如

http://www.google.com/codesearch/p?hl=en#A1edwVHBClQ/user/src/com/google/gwt/user/client/ui/Label.java

于 2010-05-18T03:10:50.007 回答
0

只需将文本放入小部件的另一个参数中,然后@UiConstructor使用该参数即可。那是:

<x:XTextBox ui:field="fieldName" label="a caption" 
  text="The text to be put in the box." />

然后你的 XTextBox.java 会有这个:

@UiField TextBox textBox;

@UiConstructor XTextBox(String label, String text) {
  initWidget(uiBinder.createAndBindUi(this));
  textBox.setValue(text);
}
于 2010-05-17T15:32:05.080 回答