我正在创建一个带有标签和TextBox的复合uibinder小部件。
意向用途是:
<x:XTextBox ui:field="fieldName" label="a caption" >
The text to be put in the box.
</x:XTextBox>我已经找到了如何使用定制的@UiConstructor构造函数来捕获标签,我可能会向构造函数添加另一个参数,但我想知道如何从@UiConstructor中获取文本,就像GWT标记<g:Label>a caption</g:Label>所做的那样。
任何帮助都是非常感谢的。
发布于 2010-05-17 23:53:11
通过查看Label小部件源代码,我发现了一个可能的实现。
关键之处在于,复合小部件必须实现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-17 23:32:05
只需将文本放入您的小部件的另一个参数中,并让您的@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-18 11:10:50
韩是对的;HasText是你需要实现的东西。我发现有一件事很方便,那就是浏览源代码,如果你知道Google小部件做了一些你也想做的事情。例如:
http://www.google.com/codesearch/p?hl=en#A1edwVHBClQ/user/src/com/google/gwt/user/client/ui/Label.java
https://stackoverflow.com/questions/2850347
复制相似问题