Not able to setTemplateContents for HtmlBoxLayout within a screen's AfterCloseListener

I am trying to change the template contents of a HtmlBoxLayout component after a screen closes by using the following code:

                PatientSubFormBrowse screen = screenBuilders.screen(this)
                        .withScreenClass(PatientSubFormBrowse.class)
                        .withLaunchMode(OpenMode.DIALOG)
                        .withAfterCloseListener(event -> {

                            htmlBox.setTemplateContents("<b>Hello</b>");

                        })
                        .build();
                screen.show();

but nothing happens. It is not working.

Is there a bug ? Or am I doing something wrong ?

Hello @robert.gilbert!

Unfortunately, HtmlBoxLayout is not able to update content at runtime. As a workaround, you can remove the old HtmlBoxLayout component and add a new one with updated content. Or you can use a Label component instead of a HtmlBoxLayout component with the following attribute: htmlEnabled=true (see sample).

Regards,
Gleb

Thanks Gleb !
Not a problem because that makes sense.
I solved my problem by removing the old component and adding a new one with updated content.

1 Like