Common widget in UiBinder

I just created a 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?

+5
source share
3 answers

Yes, you can. You need to import the package containing the class myWidgetinto the XML namespace. Say what 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>

Pay attention to import xmlns:my='urn:import:com.test.widgets'and use <my:myWidget>.

+7
source

To use your widget in Uibinder, it must implement at least the IsWidget interface. Already being widgets, he, of course, already implements IsWidget.

, - uibinder, IsWidget.

IsWidget , - asWidget(). - .

IsWidget .

,

com.zzz.client.ui.HelloKitty

, 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>

HasOneWidget.

uibinder, 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>

HTML- , , HasHTML.

+4

, , . , UiBinder, :

<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 />
</ui:UiBinder>

But what about linking to this widget in Java code? Should you also omit the generic type and anger compiler warnings?

Fortunately not. UiBinder is pretty free when it comes to types, and since typical types are just hints, you can get away with the following in Java code that supports the aforementioned UiBinder pattern:

@UiField(provided = true)
myWidget<Date> myWidget = new myWidget(new Date(), new Date());

Alternatively, you can also use the method @UiFactoryas indicated in the documentation .

0
source

All Articles