on 12-09-2014 9:03 AM
Hi All,
In controller init event I have
var myJSON = {"title":"This is Test"}
oModel.setData(myJSON);
sap.ui.getCore().setModel(oModel, "MyJSONData")
In view Create Event I have
var controls = []
controls.push(new sap.ui.commons.Label({
text:{
parts:[{path:"MYJSONData>/title"}],
formatter: function(title)
{
//will do some formatting and return formatted title
}
}
}));
but it is not binding
But when i changes controller code
as
this.getView().setModel(oModel,"MyJSONData")
It binds data(title) to View.
Question is when I set model to UI5 core object , why it never binds data but when I set model to view it binds the data.
I have several nested views within one parent view and I want same model to be used across all views. I don't want to set separate model for each view.
Any help is appreciated ,
Thanks in advance.
Hi Sanket,
Create a parent controller class and implement there the logic common for all other controllers.
In your case it is probably:
onInit : function () {
var myJSON = {"title":"This is Test"}
oModel.setData(myJSON);
sap.ui.getCore().setModel(oModel, "MyJSONData")
}
Then in sub-classes use the following:
onInit : function () {
MyGenericController.prototype.onInit.apply(this, arguments);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sanket,
I also face the same problem when I converted my app to new sap standards (while adding component.js and manifest.json). I think we cannot set the model name at core level may be because of model name conflict with other app model name.
So the solution is we can set model name with the view.
ex:
var myJSON = {"title":"This is Test"}
oModel.setData(myJSON);
// sap.ui.getCore().setModel(oModel, "MyJSONData"); // this will not work while binding
this.getView().setModel(oModel, "MyJSONData"); // this will work
similarly you get that model
var oModel = this.getView().getModel("MyJSONData");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi together,
i have the very same problem.
sap.ui.getCore().getModel(...) is empty in view!
getView().getModel() is filled with data.
i can't access data from Core model.
i created a shell so that views are only loaded if needed.
Model registration in Component.js init: function()
jQuery.sap.registerModulePath('model.ModelTaskHandler','./model/ModelTaskHandler');
jQuery.sap.require("model.ModelTaskHandler");
sap.ui.getCore().registerPlugin(new model.ModelTaskHandler('model.ModelTaskHandler'));
The model is implemented in other js object. Data load is external. But the data is correct and available.
View:
projektnameTF = new sap.ui.commons.TextField( {
value : '{task>/projektname}',
editable : false,
width : "100%"
});
If im setting the core model to the view model, it works and data load is successful!
taskmodelReadyHandler : function(channelId, eventId, data) {
this.getView().setModel(sap.ui.getCore().getModel(task), 'task');
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sanket,
sap.ui.getCore().setModel(oModel, "MyJSONData") make this model known to the framework.
Control Label is embedded in the control View and it is the Parent Control for the Label. Binding for Control Label shall not be known unless the View control is not bound the model instance.
More information can be found in the below link:
Hope this helps you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kedar,
I agree with you. But question arises that, why control always bind to view Model not to global model that we set using sap.ui.getCore().setModel(myModel, "modelName").
Up till now, I am assured that, view control will not get bind unless you set model to view or that control it self.
But It is my assumption that if model is not set to view/control then control should look global model and then bind data base on path.
Or
If control is not able to find property(path) in view/control Model then it should search in global Model for same path.
Hi Sanket
I am pretty sure that it works.
It is does not work in your case, then it has to be something else. You will likely to find the answer if you start to strip down the code around the label and check when it starts to work.
-D
Hi Sanket,
I may not be quoted on this but will try to make a logical sense.
Within a View there could be many controls and those controls would be bound to different entitysets of the Model. Hence you will have to bind the control explicitly to the Entityset by mentioning its path in the model and bind the view to just the model.
Or the other option would be to bind the model to the view and mention the path of the entityset while binding the property of the controls(something like what Dennis has done in his example).
Hope this answers your question.
Actually it just cant be exactly figured out why this doesn't work for you unless you provide a snippet replicating the issue.
Some of the possible reasons could be,
You can also try opening your console and execute sap.ui.getCore().getModel('your-model-name') to retrieve your model and find what data does the model hold.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Elango,
I have check in my code, there is not typo mistake. your 2nd point is not valid as I am able to bind when I set model to view. On 3rd point, I have check in chorme console, data is set properly to model ,
sap.ui.getCore().getModel("MyJSON") is returning proper value, it is not overridden by any other model.
Hi Sanket,
please follow the below url to know the DataBinding
Data Binding: Getting Started - User Interface Add-On for SAP NetWeaver - SAP Library
Create and set the model in index.html for sharing data to several nested views.
Thanks & Regards
Padma Mundru.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi padma,
I didn't get difference between setting model in index.html and in controller init event. Even after setting model in index.html page I am not able to view title in page.
I have already gone through the link that you have posted. Many other places I am able to bind data. but I didnt get diff why when I set Model to view it binds data and when I set model to Core() its not biding.
We will now see how to use JSON model that is globally accessible to all views of your SAPUI5 project. We will define a JSON model in Index HTML instead of a view of our application. Following code defines JSON model and sets the data to be stored when application is initially loaded. We will modify this default data by accepting user data at the runtime.
1 2 3 4 5 6 7 8 9 10 11 | var oModel=new sap.ui.model.json.JSONModel(); oModel.setData({ firstName: "Enter First Name", lastName: "Enter Last Name" }); sap.ui.getCore().setModel(oModel); |
Hi Padma,
I think you are not getting my problem.
I have set model with some name, in my case it is "MYJSONData"
so when I write
but when I write
I have binded as
Hi Padma,
Again same thing. I am able to bind data when I set model to View but when I set model to core it is not binding. I don't want to set model to view. I just pass path with model name while bind to label. why it is not picking up Model path ("title") to bind label when model is set to sap.ui.getCore().setModel, but work when I set model to this.getView().setModel
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.