on 04-25-2018 8:33 AM
Hi All,
I am passing value from one view to another view but data is not coming on send view page.
can anyone give input on same,why data is not passing on page view2.
error:
<br>
View1-Controller:
onInit: function() { //this.mymodelobject = new sap.ui.model.json.JSONModel(); jsonModel = new sap.ui.model.json.JSONModel(); },
senddata : function (){
var form_ref = sap.ui.getCore().byId("Id_simpleform1");
var objectForm = form_ref.getContent();
var myJson = {}; myJson.oName = objectForm [1].getValue();
myJson.oId = objectForm [3].getValue();
myJson.OSubject = objectForm [5].getValue();
myJson.oLocation = objectForm [7].getValue();
jsonModel.setData(myJson);
sap.ui.getCore().setModel(jsonModel);
var form_ref = sap.ui.getCore().byId("Id_simpleform1");
var view_ref = sap.ui.getCore().byId("idview2");
form_ref.removeAllContent();
form_ref.addContent(view_ref); },
view2 page:
createContent : function(oController) {
var oTextview = new sap.ui.commons.TextView({
text : "Welcome to My second page."
});
var oSimplelayoutFormview2 = new sap.ui.layout.form.SimpleForm({
id: "simpleform_v2" ,
maxContainerCols : 2,
editable: true ,
content : [
new sap.ui.commons.Label({ text : "NAME:" }),
new sap.ui.commons.TextField({ value : "{/xyz}" , width : "15em"}),
new sap.ui.commons.Label({ text : "ID:" }) , //2
new sap.ui.commons.TextField({ value : "{/Id}" , width : "15em"}) ,//3
new sap.ui.commons.Label({ text : "SUBJECT:" }) , //4
new sap.ui.commons.TextField({ value : "{/Subject}" , width : "15em"}) , //5
new sap.ui.commons.Label({ text : "LOCATION:" }) , //6
new sap.ui.commons.TextField({ value : "{/pqr}" , width : "15em"}) , //7
new sap.ui.commons.Button({
text : "SubmitData1",
width : "100px",
height : "25px",
press : oController.senddatax
})
]
});
return [oSimplelayoutFormview2 , oTextview];
Index.html:-
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.ui.commons"
data-sap-ui-theme="sap_bluecrystal">
</script>
<!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->
<script>
sap.ui.localResources("zbh_passvalue_v1_to_v2");
var view1 = sap.ui.view({id:"idview1", viewName:"zbh_passvalue_v1_to_v2.view", type:sap.ui.core.mvc.ViewType.JS});
var view2 = sap.ui.view({id:"idview2", viewName:"zbh_passvalue_v1_to_v2.view1", type:sap.ui.core.mvc.ViewType.JS});
view1.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
View1 page:-
createContent : function(oController) {
var oSimpleFormLayout = new sap.ui.layout.form.SimpleForm({
id: "Id_simpleform1" ,
maxContainerCols : 2,
editable: true ,
content : [
new sap.ui.commons.Label({ text : "NAME:" }) ,//0
new sap.ui.commons.TextField({ value : "{/xyz}" , width : "15em"}) , //1
new sap.ui.commons.Label({ text : "ID:" }) , //2
new sap.ui.commons.TextField({ value : "{/Id}" , width : "15em"}) ,//3
new sap.ui.commons.Label({ text : "SUBJECT:" }) , //4
new sap.ui.commons.TextField({ value :"{/Subject}" , width : "15em"}) , //5
new sap.ui.commons.Label({ text :"LOCATION:" }) , //6
new sap.ui.commons.TextField({ value : "{/pqr}" , width : "15em"}) , //7
new sap.ui.commons.Button({
text : "SubmitData",
width : "100px",
height : "25px",
press : [oController.senddata,oController]
})
]
});
return [oSimpleFormLayout,oButton1];
}
Hi ,
First of all its not correct way to get the property value from the form using getValue function of each input field this way you are getting the attached value of the input field not the model content .. you need to get values using the model .. You code is not following the MVC framework .. And second the model which you have set has the JSON property different than your binded property value on the form in view2.
If you could check binded properties are xvy , id , subject , pqr whereas json properties are oId , oSubject , oLocation , etc .. and also why are you usning relative binding while binding the properties (/xyz , /Id,/Subject) .. You need to use absolute binding and bindElement to the view ..
t:"NAME:" }) ,//0newsap.ui.commons.TextField({value:"{/xyz}" , width : "15em"}) , //1newsap.ui.commons.Label({text:"ID:" }) , //2newsap.ui.commons.TextField({value:"{/Id}" , width : "15em"}) ,//3newsap.ui.commons.Label({text:"SUBJECT:" }) , //4newsap.ui.commons.TextField({value:"{/Subject}" , width : "15em"}) , //5newsap.ui.commons.Label({text:"LOCATION:" }) , //6newsap.ui.commons.TextField({value:"{/pqr}" , width : "15em"})
myJson.oId = objectForm [3].getValue();
myJson.OSubject = objectForm [5].getValue();
myJson.oLocation = objectForm [7].getValue();
jsonModel.setData(myJson);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am taking help form below link
Thanks Mr. VIPLOVE KHUSHALANI
Hello,
anyone can help me..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Please check Help Link
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.