cancel
Showing results for 
Search instead for 
Did you mean: 

How to do model mapping to blocks correctly in an aggregation binding

Former Member

Hi guys!

I've been stuck for a few days now and I just can't seem to find the right documentation to solve my problem. I have an OData service that returns three levels of nested aggregations and I want to display this data in an sap.uxap.ObjectPageLayout. The first level of my OData service is bound to the sections-property of the ObjectPageLayout. The second level is bound to the subSections-Property of the ObjectPageSection-node. The third level is then bound to a list within the ObjectPageSubSection-node. Simplified, it looks like this:

<ObjectPageLayout sections="{ToRegister}">
    <sections>
        <ObjectPageSection title="{RegisterName}" titleUppercase="true" subSections="{ToDocumentType}">
            <subSections>
                <ObjectPageSubSection title="{Description}" >
                    <blocks>
                        <m:List items="{ToDocument}">
                            <m:CustomListItem>...display-code...</m:CustomListItem>
                        </m:List>
                    </blocks>
                </ObjectPageSubSection>
            </subSections>
        </ObjectPageSection>
    </sections>
</ObjectPageLayout>

For creating the project, I used the wizard "New Project from Template" and chose the template "SAP Fiori Master-Detail Application".

This works, but is very, very slow. I don't know for sure, but I suspect that it is because this code triggers the creation of many DOM objects, which might be slow within FLP Sandbox.

So I thought I'd give lazy loading a try. For this, I found it intuitive to extract the <m:List>-node and its children into a custom block. After a few hickups, I succeeded in creating the block and referencing and including it in my Detail View. I basically cut and pasted the <m:List>-node into a different file, where I put it inside of a <mvc:View>-node. This doesn't throw any errors and seems to work - but: I can't get the model data to the block! Instead of showing my list items that show some properties of the documents, it displays the text "No Data."

What my Detail View code now looks like is this:

<ObjectPageLayout sections="{ToRegister}">
    ...
         <blocks>
             <attachmentblock:Block mode="Expanded">
                 <ModelMapping externalModelName="ToDocumentType" internalModelName="Documents" externalPath="/ToDocument"/>
             </attachmentblock:Block>
         </blocks>
    ...
</ObjectPageLayout>

For clarity: "ToDocument" is a navigation property of the elements inside of the aggregation that is reached via the navigation property "ToDocumentType", which is nested the same way within the "ToRegister" property/aggregation.

In the code of my new block, I made this change to the <m:List>-node:

Before

<m:List items="{ToDocument}">

After

<m:List items="{Documents}">

Here, "Documents" is the value I used for the attribute "internalModelName" in my Detail View.

So, as I said, it now displays the text "No Data" instead of showing the actual properties of the elements in the "ToDocument" aggregation. I couldn't find a suitable example in the SAPUI5 SDK or anywhere else, and I don't know where to look. And possibly what to look for at all...

I suspect that my binding synthax is wrong, but I'm not sure and I don't know how to do it correctly. I mean, the part with the internalModelname looks simple enough, so I probably made some error with the external-parameters. Please help! There are so many examples, but none of them uses navigation properties pointing to aggregations.

Regards,

Stefan

Accepted Solutions (0)

Answers (1)

Answers (1)

minjie_lao
Product and Topic Expert
Product and Topic Expert
0 Kudos

suppose 'attachmentblock' is a separate XML view contains the List element.


you can add a controller to the attachmentblock view.

inside the controller, you can attach a matching event while attachmentblock view is initializing.

this.oRouter.getRoute("your main page route name").attachPatternMatched(this._scriptOfRoutMatched, this);

you

"your main page route name" is a route name defined in manifest.json
"_scriptOfRoutMatched" is a function to be triggered when main page is refreshed.