Question

I've recently jumped into GWT and have been happy with it.

@UiChild is nice because it allows us to add children elements programatically in addition to their representation in the UIBinder ui.xml.

However, I've found something that seems really bloated and kind of odd.

So, when I first ran into @UiChild, I thought it would work like this.

<g:FlowPanel>           
        <c:CustomWidget customWidgetParameter="I am a 
parameter"ui:field="customFieldMappingName"/>                                   
</g:FlowPanel>

@UiChild(tagname ="CustomWidget" )
     public void addCustomWidget(CustomWidget cw) 

Nice and clean. I thought that GWT would look for any "CustomWidget" tags. However, after research I found that I had to do something like this.

<g:FlowPanel>
    <c:addCustomWidget>
        <c:CustomWidget customWidgetParameter="I am a parameter"
            ui:field="customFieldMappingName"/>         
    </c:addCustomWidget>
</g:FlowPanel>

@UiChild(tagname ="addCustomWidget" )
     public void addCustomWidget(CustomWidget cw) 

Am I doing this the wrong way? Or is there some sort of reason/tiny detail that I am missing as to why its implemented like this?

Was it helpful?

Solution

Not sure if this is the reason but you could have multiple @UiChild definitions. Probably GWT doesn't use type information but only the tagname to check which function to call:

<gui:MyCustomContainer>
   <gui:myHeader>
      <g:SomeWidget>
   </gui:myHeader>
   <gui:myContent>
      <g:SomeWidget>
   </gui:myContent>
</gui:MyCustomContainer>

And in your MyCustoContainer class:

@UiChild(tagname="myHeader")
public void addHeader(Widget widget);

@UiChild(tagname="myContent")
public void addContent(Widget widget);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top