cancel
Showing results for 
Search instead for 
Did you mean: 

Named json Model binding problem in xml list to form?

Former Member
0 Kudos

hi all

i am developing an sapui5 application data comes from an oData requset i am putting my odata into a named json model and i ambinding this named model to the list in detail page

now i am having the list of attribute in detail page attribute tab

now user clicks on any attribute i want navigate to another page for editing for this what i did is

in detail.controller 

this.getRouter().navTo("attribute",{path:slectedrecid},false);

here i am passing the id of selected record and in attribute.controller

var jsonmodel = sap.ui.getCore().getModel("attributeJson");

  this.getView().setModel(jsonmodel);

  sEntityPath = "/attributes/0";

  var context = {oModel: jsonmodel, sPath: sEntityPath};

  oView.setBindingContext(context);

for testing ia am fixing the context path as attribute/0 and setting this model to this view and in attributes view

<f:content>

  <Label text="ListNumber"/>

  <Text text="{ListNumber}"/>

  <Label text="Counter"/>

  <Text text="{Counter}"/>

  <Label text="MaintenanceLevel"/>

  <Text text="{MaintenanceLevel}"/>

  <Label text="AttributeProvided"/>

  <Text text="{AttributeProvided}"/>

but the adata is not displayed .

thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Kotesh,

Let's say you have Master view and Details. There is a button on Master View called "Execute". The event attached to this button is "Execute".

You need to perform 3 steps:

  1. Send named JSON with nav.to fuction.
  2. Retrieve JSON model in Detail
  3. Bind root to your controller (in my case its table)

Master Controller Code:

handlePressExecute : function (evt) {

   // Create a Model Instance and pass it with nav.to function

var GRNSummarySetModel = new sap.ui.model.json.JSONModel();
GRNSummarySetModel.setData(data);
this.nav.to("GrnReportDetail", GRNSummarySetModel);

};

Detail View. XML:

I have bind a table to this model on detail view.

<Table xmlns="sap.m" id="idItemTable" class="tableBorder"
items="{/}" visible="true" inset="false"
width="100%" includeItemInSelection="false" showUnread="false" growingScrollToLoad="true"
noDataText="" showNoData="true" enableBusyIndicator="true"
modeAnimationOn="true" showSeparators="None" swipeDirection="Both"
backgroundDesign="Translucent" fixedLayout="false" showOverlay="false"
select="" swipe="both" growing="true" wrapping="true"
growingThreshold="100" >
<columns>
<Column xmlns="sap.m" hAlign="Center" vAlign="Middle"
visible="true">
<Text xmlns="sap.m" visible="true" text="{i18n>GrnNo}"
textDirection="Inherit" wrapping="false" textAlign="Begin">
</Text>
</Column>

</columns>

<items>
<ColumnListItem xmlns="sap.m" visible="true" type="Inactive"
unread="false" selected="false" vAlign="Middle" tap=""
detailTap="" press="" detailPress="">
<Text xmlns="sap.m" visible="true" text="{Mblnr}"
textDirection="Inherit" wrapping="false" textAlign="Begin">
</Text>
</ColumnListItem>
</items>
</Table>

Detail View Controller Code:

// On init function you can retrieve this model

grndetailView = this;
this.getView().addEventDelegate({
onBeforeShow: function(evt) { 
   grndetailView.getView().getContent()[0].scrollTo(0,0);
var data = grndetailView.getView().getBindingContext().getData();
var grnDetailPageModel = new sap.ui.model.json.JSONModel();
grnDetailPageModel.setData(data);
grndetailView.getView().setModel(grnDetailPageModel);
}
});

    },

Hope this will resolve your issue.

Thanks and regards

Abhijeet

Former Member
0 Kudos

i want the context of the clicked record in list and bind it into next view in that i am editing the selected record in detail view

i am binded the named model to the next page with static context it is not displaying data that is my problem

Former Member
0 Kudos

Hi Kotesh,

  1. Are you able to retrieve JSON Model in detail view ?  In my case I am I am retrieving selected data into table based on JSON Model property [aSelectedPath]

For Example:

var oTable = selfView.byId("Master--idItemTable");

oTable._aSelectedPaths // This give you selected record.

Can you please explain what is you exact requirement ?

What do you mean by static Context ?

Try Below binding:

f:content>

  <Label text="ListNumber"/>

  <Text text="{jsonmodel>/ListNumber}"/>

  <Label text="Counter"/>

  <Text text="{jsonmodel>/Counter}"/>

  <Label text="MaintenanceLevel"/>

  <Text text="{jsonmodel>/MaintenanceLevel}"/>

  <Label text="AttributeProvided"/>

  <Text text="{jsonmodel>/AttributeProvided}"/>

Former Member
0 Kudos

Hi abhijeet,

my requirement is i am able to show the named model data in list

when user clicks on list items he will navigate to another view attribute.xml

in that i am having an form here i need to bind the selected record data

for this i am doing like below

accessing the json model in attribute.controller ------> var jsonmodel = sap.ui.getCore().getModel("attributeJson").

and binding the json model to the view ------>  this.getView().setModel(jsonmodel);

setting binding context to view ------>

                                                               sPath = "/attributes/0";

                                                             var context = {oModel: jsonmodel, sPath: sPath};

                                                               oView.setBindingContext(context);

so now t need render on this view but not showing.

Former Member
0 Kudos

Hi Kotesh,

  1. What is the control you are binding on view 3 ?
  2. I am assuming that you are getting the data in jsonmodel ?
  3. Is your view XML ? if yes can you post your XML control code.

Thanks and Regards

Abhijeet

Former Member
0 Kudos

Hi abhijeet

i solved my problem with named models its working fine now.

Former Member
0 Kudos

Hi Kotesh,

That's a good news..... I will appreciate if you can share your solution. This will help others.

Please close this thread with Solution.

Thanks and Regards,

Abhijeet

Former Member
0 Kudos

in detail view i am having list controle like below

<List  items="{path: 'mainModel>/Attributes' }     

                >

<items>
<ObjectListItem

        title="{mainModel>AtrDescription}"

        type="Active"

        press="onListItemPress"

        number="{mainModel>AttributeValueProvided}" >

and in detail controller:

onListItemPress: function(oEvent) {

  var sEntityPath = oEvent.getSource().oBindingContexts.mainModel.sPath;

  var index = sEntityPath.lastIndexOf("/");;

  var sPath =sEntityPath.substr(index+1);

  this.getRouter().navTo("attribute", {

  from: "detail",

   entity: sPath

  });

in attribute view

<Label text="AttributeName"/>

  <Text text="{mainModel>AtrDescription}"/>

  <Label text="AttributeValueProvided"/>

  <Input value="{mainModel>AttributeValueProvided}"/>

      <Label text="Description"/>

  <Text text="{mainModel>Description}"/>

in attribute controller:

bindView: function(sEntityPath) {
var oView = this.getView();
varbindPath = "mainModel>/Attributes" + sEntityPath;
     oView.bindElement(bindPath);
},

Answers (0)