Cannot pass model data from aggregation binding to block for lazy loading in xml view

Viewed 1020

I'm building an SAPUI5 Fiori application from the project template "SAP Fiori Master-Detail Application" in SAP Web IDE. I connect to an OData Service that gives me this nested structure (bold text represents a navigation property):

  • File
    • Properties...
    • ToRegister (returns collection of Registers)
      • Properties...
      • ToDocumentType (returns collection of DocumentTypes)
        • Properties...
        • ToDocument (returns collection of Documents)
          • Properties...

Displaying data in the Detail View is very slow, so I'm trying to use sap.uxap.ObjectPageLayout's lazy loading feature. For that, I have to extract parts of my view and put them into a custom block. This is accomplished by deriving from sap.uxap.BlockBase, according to this example (code here). Unfortunately, I couldn't find any examples that use aggregations/aggregation bindings.

I use XML Views. My Detail View looks like this:

<mvc:View 
    xmlns="sap.uxap"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:m="sap.m">
    <ObjectPageLayout sections="{ToRegister}">
        <sections>
            <ObjectPageSection title="{RegisterName}" subSections="{ToDocumentType}">
                <subSections>
                    <ObjectPageSubSection title="{Description}" >
                        <blocks>
                            <m:List items="{ToDocument}">
                                <m:CustomListItem>
                                    ...code for displaying properties...
                                </m:CustomListItem>
                            </m:List>
                        </blocks>
                    </ObjectPageSubSection>
                </subSections>
            </ObjectPageSection>
        </sections>
    </ObjectPageLayout>
</mvc:View>

This code does not use custom blocks. This is the slow version, but it works and displays the data correctly. Notice that the bold navigation properties are placed in curly braces (e.g. <m:List items="{ToDocument}">).

For my custom block, I extracted the <m:List> part into a seperate view:

<mvc:View 
    xmlns="sap.uxap"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:m="sap.m">
    <m:List items="{Documents}">
        <m:CustomListItem>
            ...code for displaying properties...
        </m:CustomListItem>
    </m:List>
</mvc:View>

Notice here that the property in the curly braces is not {ToDocument} anymore but {Documents}. That's because of the model mapping that has to be introduced in the original Detail View for this to work (see section Model Mapping in this article). I modified the Detail View like this:

<mvc:View 
    xmlns="sap.uxap"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:m="sap.m"
    xmlns:attachmentblock="pft7.blocks.FileAttachmentList">
    <ObjectPageLayout sections="{ToRegister}">
        ...
        <blocks>
            <attachmentblock:Block mode="Expanded">
                <ModelMapping 
                 externalModelName="ToDocumentType"
                 internalModelName="Documents"
                 externalPath="/ToDocument" />
            </attachmentblock:Block>
        </blocks>
        ...
    </ObjectPageLayout>
</mvc:View>

It's pretty much the same. I added the xml namespace attachmentblock (which points to my custom block) and used it to replace the <m:List> child of <blocks>. Notice the attribute internalModelName of the <ModelMapping> node. It can be freely chosen and just has to be the same as the model name used in the block's view.

Finally, the problem: With this modification, my Detail View does not display the document properties anymore. Instead, it just displays the text "No data". I added some dummy text and it was properly displayed in my Detail View, so the actual inclusion of the custom block itself seems to work.

I suspect that I got the <ModelMapping> part wrong, but I don't know how to set the attributes correctly. I couldn't find any examples that use aggregations and navigation properties for this, so I'm pretty clueless. The console does not log any errors.

1 Answers

Can you check whether it works if you use an “Object Page with LazyLoading without blocks” as seen in this sample here?

In addition to this, you might also want to check on the reasons for the slow “Display of Detail View” via OData service. Very often this is caused by long database access times. If your backend is an R/3-ABAP system, you might want to check your OData service with an SQL-Trace (transaction ST05) for long database response times caused by unnecessary requests or missing indexes.

Related