cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Second fragment on Object Page not getting the binding context

catalinfeidi
Participant
1,136

Hi guys,

I'm having a Fiori Adaptation project and I'm trying to add 2 fragments on same object page using SAPUI5 Visual Editor.

The fragments have only a Smart Table but want to display different data. They look almost the same, the only difference is the EntitySet which is being displayed.

Fragment XML Annotation(second one is the same but with a different EntitySet and different beforeRebindTable method)

<core:FragmentDefinition 
xmlns:core='sap.ui.core'
xmlns='sap.m'
xmlns:uxap='sap.uxap'
xmlns:table="sap.ui.table"
xmlns:u="sap.ui.unified"
xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
xmlns:smartTable="sap.ui.comp.smarttable"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
>
<uxap:ObjectPageSection id="idOPS1" title="Material Data">
<uxap:subSections>
<uxap:ObjectPageSubSection id="idOPSS1" title="Material Data">
<uxap:blocks>
<VBox id="idVboxMain" fitContainer="true">
<Text id="idTextSection"></Text>
<smartTable:SmartTable
id="id1SmartTable"
entitySet="Z_C_MATERIAL_DATA"
tableType="ResponsiveTable"
beforeRebindTable=".extension.customer.changeRecord2.DetailsExt.onBeforeRebindTable1"
useVariantManagement="true"
useTablePersonalisation="true"
header="Material Data"
showRowCount="true"
enableAutoBinding="true"
class="sapUiResponsiveContentPadding"
showFullScreenButton="true"
placeToolbarInTable="true"
initiallyVisibleFields="Material, Plant"
initialNoDataText="Loading..."
requestAtLeastFields="Material">
<smartTable:layoutData >
<FlexItemData growFactor="1" baseSize="0%" id="idFid1"/>
</smartTable:layoutData>
</smartTable:SmartTable>
</VBox>
</uxap:blocks>
</uxap:ObjectPageSubSection>
</uxap:subSections>
</uxap:ObjectPageSection>
</core:FragmentDefinition>

Because I want to filter the Smart Tables based on the Object Page Reference ID(Material ID) I have to get the binding context of the view to know for which material I need to display the data in both fragments. For the first one, it's working. For the second fragment, not.

Each smart table has its own method on beforeRebindTable.

This is how I'm getting the context and pushing it to the filter of Smart Table within the controller:

                var bindingContext = this.getView().getBindingContext();
var path = bindingContext.getPath();
var odisplayedData = bindingContext.getModel().getProperty(path);
if (odisplayedData) {
var oFilter = new sap.ui.model.Filter({
filters: [
new sap.ui.model.Filter("Material", sap.ui.model.FilterOperator.EQ, odisplayedData.Material),
],
and: true
});
binding.filters.push(oFilter);
}
},

For the smart table from the first fragment it works perfectly. If I put the same piece of code into the beforeRebindTable's method of the smart table from the second fragment, I receive undefined when calling getBindingContext() for the second fragment's smart table. 😞

Do you have an idea what could be the root cause?

Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

RaminS
Active Participant
0 Kudos

How do you declare your fragments? Maybe your controller context is not passed to the second fragment. Put a breakpoint before the line:

var bindingContext = this.getView().getBindingContext();

of the second fragment, and see if "this" is defined.

catalinfeidi
Participant
0 Kudos

Hi Ramin,


“this” is defined there. What do you mean by “how do you declare fragments”?

Thank you!

RaminS
Active Participant
0 Kudos

If this is defined, and this.getView() is defined but this.getView().getBindingContext() is undefined, it means your fragment gets loaded before the view gets bound to the context.

There are different ways of loading fragments, loadFragment(), or sap.ui.core.Fragment.load() etc. depending on the ui5 version you are using.

This may help:

https://ui5.sap.com/#/topic/04129b2798c447368f4c8922c3c33cd7

.

nimnu07
Discoverer
0 Kudos

Hi Ramin,

I do have version 1.19(before loadFragment() was introduced). I checked the documentation but it's hard to get exactly how the fragment should be called just to be bound to the context of object page. Moreover, I don't get why the first fragment works.

If the fragment/section/subsection is the first one, above all others, just only the one from the top works with the bindingcontext.

Thank you!

RaminS
Active Participant
0 Kudos

1.19? ... really? wow, that's pretty low.

So how do you load the fragments? something like this?

Fragment.load({
	name: "...extension.customer.changeRecord2.DetailsExt",
        controller: this
});

In Javascript the order of the code doesn't matter, things happen asynchronously, so it doesn't matter if the code is at the top or not. In the controller method you posted, what does the variable binding point to?

nimnu07
Discoverer
0 Kudos

I'm having adaptation project, I don't have to load fragments manually.