sapui5 - Method getPath called in onBeforeRendering returns undefined -


i have list report which, once selected item, prompts object page. using no fiori elements, created scratch. object page has static header, body changes item item. in essence, body uses different fragments depends on field (position type) of selected item. in other words:

  • pos type 1 ---> fragment a
  • pos type 2 ---> fragment b

to this, on controller of object page, have implemented following withing onbeforerendering lifecycle method:

    onbeforerendering: function() {         // // set fragment used         var olayout = this.getview().byid("objectpagelayout"),              ofragment = sap.ui.xmlfragment(this._fragmentname());         olayout.addsection(ofragment);       },     _fragmentname: function() {         var omodel = this.getview().getmodel();         var spostype = omodel.getproperty(this.getview().getobjectbinding().getpath() + "/positiontype");         var sfragment;          if (spostype === "1") {             sfragment = "a";         } else if (spostype === "2") {              sfragment = "b";         }         return sfragment;     }, 

the problem facing code throwing following error message: "uncaught (in promise) typeerror: cannot read property 'getpath' of undefined"

the way found make work by, instead of using method onbeforerendering, used oninit. way, getpath() works fine. if user goes list report, , selects item of different position type, object page displays same fragment used in previous item selected.

in case wonder, bellow find object view:

<mvc:view height="100%" xmlns="sap.uxap" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:m="sap.m" xmlns:semantic="sap.m.semantic" xmlns:forms="sap.ui.layout.form" xmlns:layout="sap.ui.layout" controllername="objectview.controller" xmlns:aud="sap.uxap.sample.sharedblocks.fragmentblocks"> <semantic:fullscreenpage id="page" navbuttonpress="onnavback" shownavbutton="true" title="{i18n>objectpagetitle}"> <m:page title="object page title">     <m:content>         <objectpagelayout id="objectpagelayout">             <headertitle>                 <objectpageheader id="itemtitle" objecttitle="item title">                     <actions>                         actions defined                      </actions>                 </objectpageheader>             </headertitle>             <headercontent>                 header content             </headercontent>             <sections>              </sections>         </objectpagelayout>     </m:content>     <m:footer>         <m:bar>             <m:contentright>                 buttons added footer             </m:contentright>         </m:bar>     </m:footer>      </m:page> </semantic:fullscreenpage> 

what happens each time go page add new section on container of sections.

you can remove existent sections before adding new one.

olayout.removeallsections(); olayout.addsection(ofragment); 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -