cancel
Showing results for 
Search instead for 
Did you mean: 

Display odata values in Fragments

Former Member
0 Kudos

Hi,

I have a button in my xml view which displays a popup on button click. I am able to display the popup using the concept of fragments. Now I want to display the data to these fragment from the odata dynamically. I have attached my fragment code (PFA).

Since this is the first view for my app I am not able to display data here but I am able to see the data if I bind it to a table.

Please provide your valuable suggestions. Waiting for a quick reply.

Thanks,

Srinivasan

Accepted Solutions (0)

Answers (3)

Answers (3)

PMarti
Active Participant

Hi,

You need inherit models from view.

try: this.getView().addDependent(oFragmentInstance)

Regards,

Pau

Former Member
0 Kudos

Hi Pau,

I had tried your suggestion and got Error: "/ServiceRequestCollection" is not valid for aggregation "dependents" of Element sap.ui.core.mvc.XMLView#__xmlview2(…).

Regards,

Srinivasan

Former Member
0 Kudos

I had followed the link OpenUI5 SDK - Demo Kit for another fragment. I am able to display the data from the model there since it is view got by passing values to another view.

tunakaner
Participant
0 Kudos

Cheers pmarti

Former Member
0 Kudos

Hi,

I tried to bindElement with the id of the record I want to display. Still the data does not display in the fragment. Is there any other control where I can display some fields with their labels?

Regards,

Srinivasan

Former Member
0 Kudos

Hi Srinivasan,

Did you bind the element or the property in the controller and also how you have included the fragment in your code  in the view or in the controller?

Thanks

Viplove

Former Member
0 Kudos

Hi Viplove,

I have included the fragment using the below code in the controller of that view.

createticket: function(oEvent) {

            // create popover

            if (!this._oPopover1) {

                this._oPopover1 = sap.ui.xmlfragment("popoverNavCon", "CustomerPortal.Popover", this);

                this.getView().addDependent(this._oPopover1);

            }

            // delay because addDependent will do a async rerendering and the popover will immediately close without it

            var oButton = oEvent.getSource();

            jQuery.sap.delayedCall(0, this, function() {

                this._oPopover1.openBy(oButton);

            });

        },

Further I added the model to the controller by

var oModel = new sap.ui.model.odata.ODataModel("/sap/c4c/odata/v1/c4codata/");
   this.getView().setModel(oModel);
  

this.getView().addDependent("/ServiceRequestCollection");

Former Member
0 Kudos

Hi Srinivasan,

You added the fragment as dependent that's correct : this.getView().addDependent(this._oPopover1);

this will make the model available to the fragment too, but you need to bind the entitySet to the container using bindElement() like this :

var container = sap.ui.core.Fragment.byId("popoverNavCon", "navCon");

//getting id of a fragment if fragment id is provided

//you can even use the page id instead of navCon(NavContainer id)

container.bindElement("/ServiceRequestCollection");

//binding entitySet to the container(parent), this will allow the child to //use the relative binding.


references:

1. Element Binding - User Interface Add-On for SAP NetWeaver - SAP Library

2. Retrieving Control Instances by their ID - UI Development Toolkit for HTML5 (SAPUI5) - SAP Library


thanks

Viplove


junwu
Active Contributor
0 Kudos

what is

this.getView().addDependent("/ServiceRequestCollection");

????

Former Member
0 Kudos

It is one of the suggestions in the previous comments to inherit model from view

Former Member
0 Kudos

Instead of adding the fragment I had put my entityset name by mistake

junwu
Active Contributor
0 Kudos

then?

Former Member
0 Kudos

Hi Srinivasan ,

Adding this.getView().addDependent(this._oPopover1); will inherit the model ..

Just bindElement to the container , it will solve your issue.

thanks

Viplove

Former Member
0 Kudos

I will try the same and update as you have suggested in the previous comment

Former Member
0 Kudos

Hi Viplove,

I have changed the fragment code displaying the fields in a form for alignment purpose.

Do I still use bindElement in my controller. Below is the controller code regarding the popup

onLoad: function(oEvent) {

                if (!this._oPopover1) {

                this._oPopover1 = sap.ui.xmlfragment("customerpopupNavCust", "CustomerPortal.CustomerPopup", this);

                this.getView().addDependent(this._oPopover1);

                this._oPopover1.bindElement("/ServiceRequestCollection");

            }

            var oButton = oEvent.getSource();

            jQuery.sap.delayedCall(0, this, function() {

                this._oPopover1.openBy(oButton);

            });

        },

I have also changed the name of NavContainer id to "navCust".

junwu
Active Contributor
0 Kudos

if it is already working,  do you think it is still needed?

Former Member
0 Kudos

I have changed the name of the fragment id but still the did not get the data dynamically

junwu
Active Contributor
0 Kudos

you have to bind to right elemnt

something like

.bindElement("/ServiceRequestCollection(1000000000)");

Former Member
0 Kudos

"1000000000" can be the ID from the odata also?

junwu
Active Contributor
0 Kudos

id of the record, you are trying to show

Former Member
0 Kudos

But isin't this similar to hard coding except that the binding takes place for a specific record.

junwu
Active Contributor
0 Kudos

i just give you an example, you have to specify the record, then your fragment can display the corresponding data

did u ever study the sample app from sap?

Former Member
0 Kudos

My bad Jun, Can you please share the link regarding the sample app?