on 04-17-2015 6:49 PM
Hi,
We are extending the Price and Availability app.
We have two views S2 and S3.
S2 is a search screen where we input some values and on click of a button, we need to show the gateway results in S3 which is a detail screen
We have a S2 controller where in the action handler, we are calling a gateway service and creating a json model for the odata results.
Now, we want to use the results in S3 view. How to get the json model in S3. We are aware that we can get it in S3 Controller using sap.ui.getCore.getModel('Modelname');
But our question is in which method of controller, I need to call the getCore statement. I tried in init() method of S3 but it is called before the action handler of S2.
My requirement is I need to bind the results to S3 view which are retreived in S2 controller.
I am attaching the files of S2 and S3 for your reference. Please help.
Regards
V
this.oRouter.attachRouteMatched($.proxy(function(oEvent) {
sap.ui.getCore().getModel("MaterialAvailabilityModel");
}, this), this);
binding format is "MaterialAvailabilityModel>/PATH"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you do
this.oRouter.navTo("detail", !jQuery.device.is.phone);
ar the end of the method, that should fire a routeMatched event
this.oRouter.attachRouteMatched($.proxy(function(oEvent) {
//This will be executed when navTo is called
}, this), this);
As alternative you can fire event once data is loaded
in S2 search event handler after model is created and stored
var oComponent = sap.ui.core.Component.getOwnerComponentFor(this.getView());
oComponent.getEventBus().publish("app", "search", { model : oMaterialAvailability} );
in S3 in onInit
var oComponent = sap.ui.core.Component.getOwnerComponentFor(this.getView());
oComponent.getEventBus().subscribe("app", "search", this._search, this);
define
_search: function(sChannel, sEvent, oData){
//oData contains oModel with oMaterialAvailability
}
But again, routerMatched should work
Hi Maksim Ranshchynski,
routeMatched() is working only for the first time when the view is called.
But if the user provided the input data again with new values and clicks on the button the routeMatched() was not getting called for the second time. In such cases, what is the best method to call the gateway service again.
Regards
V
As maksim said, routePatternMatched event gets triggered everytime you navigate. For example if you are navigating from s2 to s3 , then in s3 controller you can do this.
onInit: function(){
this.router = sap.ui.core.UIComponent.getRouterFor(this);
this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
},
_handleRouteMatched : function (evt) {
// Write your logic here
sap.ui.getCore().getModel("MaterialAvailabilityModel");
}
in S2
search: function (oEvent) {
var that = this;
var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZXX_PRICE_AVAIL_SRV_01/");
oModel.read("MaterialAvailabilitySet", null, ["$filter=simMatnr eq '000000000088242626' and simWerks eq 'SLMO' and simKunag eq '100412' and simKunwe eq '8000842'"], true,
function(oData, oResponse) {
var oMaterialAvailability = new sap.ui.model.json.JSONModel(oData.results);
sap.ui.getCore().setModel(oMaterialAvailability, "MaterialAvailabilityModel");
this.oRouter.navTo( "detail", !jQuery.device.is.phone);
}
);
}
i dont really know the reason, hard to say as it is an extension and without original component hard to guess. try to fire an event as i suggested earlier
in S2 search event handler after model is created and stored
var oComponent = sap.ui.core.Component.getOwnerComponentFor(this.getView());
oComponent.getEventBus().publish("app", "search", { model : oMaterialAvailability} );
in S3 in onInit
var oComponent = sap.ui.core.Component.getOwnerComponentFor(this.getView());
oComponent.getEventBus().subscribe("app", "search", this._search, this);
define
_search: function(sChannel, sEvent, oData){
//oData contains oModel with oMaterialAvailability
}
I found the root cause why oRouter.attachRouteMatched is not getting called.
We are not able to see the back navigation button in when we run the application in desktops and tablets.
In mobile devices, we are able to see the back navigation button and the method is getting called.
Any idea on why the nav button is not visible in desktops and tablets.
Regards
V
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.