문제

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?

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top