Adam Harkus
Adam Harkus

Reputation: 2210

SAPUI5 View only clearing on refresh, how do I re-initialise the view contents?

I'm using a component in my view so that I can setup a placeholder div.

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml"
controllerName="CompleteSurvey.controller.CompleteSurvey">
<App>
    <pages>
        <Page title="{view>/surveyInfo/Name}">
            <content>
                <Text class="sapUiSmallMargin" text="{view>/siteInfo/SearchString}" id="__title0" width="auto" textAlign="Center"/>
                <core:HTML content="<div id="panelContent"><div>"></core:HTML>
            </content>
        </Page>
    </pages>
</App>

I'm then creating compenents in the controller, and placing them at the "panelContent"

var oPanel = new sap.m.Panel({
expandable: true,
expanded: false,
headerText:oData.results[0].CategoryDesc
id: "Panel" + oViewData.surveyInfo.SurveyId + index
});

oPanel.placeAt("panelContent");

Work fine first time in, or if I refresh the page.

However, if I simply hit the back key, and go in again, unfortunately the content within "panelContent" isn't cleared, another panel is created in addition to my original one.

Please advise....

Upvotes: 0

Views: 1505

Answers (1)

Andrew Naumovich
Andrew Naumovich

Reputation: 1450

You use term "component" but I guess that you are talking about UI5 controls, however there is a term "component" in UI5 too, so please do not mix them up, they are different things.

The behavior that you described looks absolutely correct. Read the documentation of "placeAt" method here.

Without any extra parameters, it simply adds one more control into container. According to the documentation, you can use "only" parameter to automatically remove the existing stuff within container.

You should bear in mind that if you use "only" approach, the existing controls in the container won't be destroyed, so the will lay in memory, I think that they should be destroyed manually.

Upvotes: 1

Related Questions