I just created widget:
public class myWidget<T> extends FlowPanel {
private T value;
public T getValue()
{
return value;
}
public myWidget(T[] values) {
for (T value : values)
{
//do action
}
}
How can I add it using UiBinder? Is it possible at all?
Yes you can. You have to import the package which contains the myWidget
class into an XML namespace. Say your package is called com.test.widgets
, the declarative layout looks like this:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:my='urn:import:com.test.widgets'>
<my:myWidget>
<g:Label>A label</g:Label>
<g:Label>A second label</g:Label>
</my:myWidget>
</ui:UiBinder>
Note the import xmlns:my='urn:import:com.test.widgets'
and the usage <my:myWidget>
.
To have your widget usable in Uibinder it must implement at least IsWidget interface. Being a widget already, it of course already implements IsWidget.
Therefore, any non-widget could also be used as a child widget element in uibinder by having it implement IsWidget.
The IsWidget interface requires the non-widget to implement the method asWidget()
. Therefore, such a non-widget would have to act as a widget container.
Implementing IsWidget will only allow the class to be used as a child widget element.
Let's say your class is
com.zzz.client.ui.HelloKitty
In order for it be able to have child widget elements, it must implement HasWidgets
.
<ui:UiBinder
xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:z='urn:import:com.zzz.client.ui'>
<g:VerticalPanel>
<z:HelloKitty>
<g:button ..../>
<g:textbox>asdf</g:textbox>
</z:HelloKitty>
<g:VerticalPanel>
</ui:UiBinder>
Or, it could also just implement HasOneWidget.
In order to allow the class to have text between its uibinder tags, it must implement HasText.
<ui:UiBinder
xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:z='urn:import:com.zzz.client.ui'>
<g:VerticalPanel>
<z:HelloKitty>qwerty</z:HelloKitty>
<g:VerticalPanel>
</ui:UiBinder>
In order to accept valid HTML between its tags, I believe you should have it implement HasHTML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With