Skip to Content
avatar image
Former Member

onAfterRendering Event called twice & SAPUI5 version : “1.46.8”

H! All,

Please help me on this.

Thanks in advance.

-- Hemal Suthar

Scenario 1:

sample.view.xml

<mvc:View xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
    controllerName="Sample.controller.EmpStat" xmlns:html="http://www.w3.org/1999/xhtml">
    <Page id="EmpStat" showHeader="false">
        <content>
    <HeaderContainer id="gridDOJ" scrollStep="200" scrollTime="200" orientation="Horizontal" height="65px"></HeaderContainer>
</content>
    </Page>
</mvc:View>

sample.controller.js

onAfterRendering: function() {
    alert("Test");      
}

Note: Here afterRendering() event is called two times.

Scenario 2:

sample.view.xml

<mvc:View xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
        controllerName="Sample.controller.EmpStat" xmlns:html="http://www.w3.org/1999/xhtml">
        <Page id="EmpStat" showHeader="false">
            <content>
    <l:Grid id="gridDOJ" defaultSpan="L3 M4 S6">
            <l:content></l:content>
    </l:Grid>
</content>
        </Page>
    </mvc:View>

sample.controller.js

onAfterRendering: function() {
        alert("Test");      
}

Note: Here afterRendering() Event is called one time only.

why in Scenario 1 event is called twice?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Jul 06, 2017 at 10:07 AM

    Hi Hemal,

    After addition of HeaderContainer to sap.m Lib from 1.44

    HeaderContainer has a borrowed class onAfterRendering. from sap.ui.core.control, hence in scenario one headerContainer calls this method once and sap.m.Page calls the method another time. if you use an oEvent in the method like this

    onAfterRendering:function(oEvent){
        alert("Test");      }

    you can use a validation to findout which is the parent control that is calling this event and distinguish for your case.

    regards

    GB

    Add comment
    10|10000 characters needed characters exceeded