cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Context transfer

MariusStoica
Active Participant
0 Kudos

Hi guys,

I'm having a problem transferring 2 OData models to the same page. I'm not using spitapp. Let me explain

I have 3 pages.

In the first page I navigate from a list with :

handleListSelect : function (evt) {

var app = sap.ui.getCore().byId("App--app");

var context = evt.getParameter("listItem").getBindingContext();

app.to("App--orderView", context);

},

and when I get in the "Order" page, I do this:

onInit : function(evt) {

  // binding model synchronisation

  this.getView().addDelegate({ onBeforeShow: function(evt) {

   if (this.direction != "back") {

    evt.to.setModel(evt.data.oModel);

    evt.to.setBindingContext(evt.data);

   } //endif

  } //endfunc onBeforeShow

  }); //endDelegate

},

On the Order page, I have the "Add product button" that takes me to the third page.

From that page, I navigate back to the Order page using something similar to the first navigation:

onAddPress : function (oEvt) {

  var aContexts = this.getView().byId("idMaterialsList").getSelectedContexts(true);

  var app = sap.ui.getCore().byId("App--app");

  app.to("App--orderView", aContexts);

}

But when I get back to the Order page, from the Materials page 2 things happened:

1. The data from the first oModel gets overwritten by the new data from the new oModel

2. The selected from the Materials list doesn't show up in the Order items list:

    <List id      ="idMaterialsList"

      items     ="{/Materials}"

            selectionChange   ="onSelectionChange"

            mode     ="MultiSelect"

      includeItemInSelection ="true">

     <!-- <items> -->

      <ObjectListItem

       title="{Material}"

       type="Inactive"

       number="11"

       numberUnit="numberUnit"

       press="handleListItemPress"  >

       <attributes>

        <ObjectAttribute text="{Description}" />

       </attributes>

       <firstStatus>

        <ObjectStatus text="3"/>

       </firstStatus>

      </ObjectListItem>

     <!-- </items>-->

    </List>

Any idea how can I improve this ?

Thank you,
Marius

Accepted Solutions (0)

Answers (2)

Answers (2)

SergioG_TX
Active Contributor
0 Kudos

you can do two things:

1) add multiple models to the global core object then you need to access the model and its data

2) you can create one model with different properties. once you create the model, then you can do this.

oModel.setData({ dataSetA: someData, dataSetB: someOtherData });

then you can access those data sets independently on the same page with the relative path

hope this helps.

MariusStoica
Active Participant
0 Kudos

My model contains the service which is like this (since I'm using SMP 3.0):

http://ip:port/com.app/


with all the collections in it /Materials, /SalesOrderHeader, /SalesOrderItems, /Clients.

So in my case, when I use oModels, I already have reference to all of these (Right?).

In the first screen when I select the client for my order, I'm using the model oModel/Clients, more precisely:


<List

  items="{/Clients}"

  <!-- <items> -->

  <ObjectListItem

  title="{Name}"

  type="Inactive"

  </ObjectListItem>

  <!-- </items>-->

  </List>

and in the third screen I have something similar for the materials oModel/Materials:


    <List

     items     ="{/Materials}" >

     <!-- <items> -->

      <ObjectListItem

       title="{Material}"

      </ObjectListItem>

     <!-- </items>-->

    </List>

Now in the second screen, for orders, should I use the "/SalesOrderHeader, /SalesOrderItems" colections ?

Because at the moment I just import the model that is in the "context" and go from there. I imagine that it's not the perfect way, but how do I create a oModel with only those two collections?

There is something I'm missing in the app design or logic. Even if I wirte "oModel.setData({ dataSetA: someData, dataSetB: someOtherData });" how do the elements in my Order screen know how to extract the data from the correct oModel?

Can you shade some light onto it?

Thank you,

Marius

SergioG_TX
Active Contributor
0 Kudos

you need to bind items to the correct data set. then each of the items have the item termplate which will bind to the specific properties within the data set

kai2015
Contributor
0 Kudos

Hi,

what about giving your second model a name? So the first one will not be overwritten ...

kind regards

Kai

MariusStoica
Active Participant
0 Kudos

And do you see it work ? Can you elaborate on your idea ?

kai2015
Contributor
0 Kudos

Ok, eh just let me summarize your case:

  • - 3 Pages: Materiallist, Orderlist, AddOrder
  • - With page AddOrder, you want to update the OrderModel
    • After adding an order, your model contains only the recently added order and not the whole data of your orders.
    • When you go back to the order page, the app has lost the binding of the selected material, so it doesn’t show the order list.

Is that all right?

Maybe you can build a small example of your app here?

http://jsbin.com/?html,js,output

kedarT
Active Contributor
0 Kudos

I provided solution for this in your other thread-  . Let me know if it helps.