GWT: How can I reinitialize a widget in UI binder discarding all changes obtained during its life cycle?

StackOverflow https://stackoverflow.com/questions/23213903

  •  07-07-2023
  •  | 
  •  

Pregunta

I have a UI-binder-driven composite that consists of a lot of widgets and it is used to render item-specific information. Let's say, it's just a composite like this:

...

<g:FlowPanel ui:field="itemPanel">
    <g:Label ui:field="title"/>
    <g:Label ui:field="description"/>
    <w:CustomPanel>
        <w:CustomFoo ui:field="foo">
            ...
        </w:CustomFoo>
        <w:CustomBar ui:field="bar">
            ...
        </w:CustomBar>
    </w:CustomPanel>
</g:FlowPanel>

<g:FlowPanel ui:field="itemPanel2">
    ...
</g:FlowPanel>

...

At some point I need to hide the first panel, using the the hide() method. However, the hide() method can be not enough if there's intention to recreate (or reinitialize) the itemPanel panel, and probably free DOM resources that might be allocated for the CustomFoo and CustomBar components. Please note that itemPanel.clear(); destroys all nested widgets, so a consecutive call like title.setText(...) has no any effect because the DOM is destroyed in this scenario.

How can I recreate the itemPanel as if it has just been loaded from its UI binder again?

Thanks in advance.

¿Fue útil?

Solución

Make ItemPanel a widget. Then you can use:

myCompositeWidget.remove(panel1);
ItemPanel panel2 = new ItemPanel();
myCompositeWidget.add(panel2);

You can use insert() instead of add(), if you need a specific position.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top