GWT Combined Composition

I am creating a composite widget widget with a shortcut and a text box.

Preferred Use:

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

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

Any help is appreciated.

+3
source share
3 answers

I found a possible implementation by looking at the source code of the Label widget.

The key point is that the composite widget must implement the HasText interface. therefore, in the declaration and in the body:

public class XTextBox extends Composite implements HasText ...
...
@UiField TextBox textBox;
...
public void setText(String text) {
    textBox.setText(text);
}
public String getText() {
    return textBox.getText();
}
...
+3
source

@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);
}
0

Khan is right; HasText is what you need to implement. One thing that I found convenient is to look at the source if you know that the Google widget does what you would like to do. eg.

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

0
source

Source: https://habr.com/ru/post/1745812/


All Articles