Hi,
i have created a login page and a welcome page. i am able to navigate to the next page(ie : LOGIN page TO WELCOME page) but i am trying to get the user data into the welcome page, but i am unable to do it. Please help.
have attached the screenshot.
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,sap.ui.ux3"
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("testlogin");
var oShell = new sap.ui.ux3.Shell({
id: "shell1",
});
var loginView = sap.ui.view({
id: "loginView",
viewName : "testlogin.loginpage",
type: sap.ui.core.mvc.ViewType.JS
});
var welcomepageView = sap.ui.view({
id: "welcomeView",
viewName : "testlogin.welcomepage",
type: sap.ui.core.mvc.ViewType.JS
});
//var view = sap.ui.view({id:"idloginpage1", viewName:"testlogin.loginpage", type:sap.ui.core.mvc.ViewType.JS});
//view.placeAt("content");
oShell.setContent(sap.ui.getCore().byId("loginView"));
// oShell.addContent(sap.ui.getCore().byId("loginView"));
oShell.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
LOGIN PAGE VIEW
sap.ui.jsview("testlogin.loginpage", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf testlogin.loginpage
*/
getControllerName : function() {
return "testlogin.loginpage";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* @memberOf testlogin.loginpage
*/
createContent : function(oController) {
//var aControls = [];
var userName = new sap.ui.commons.TextField("UserName");
userName.setEnabled(true);
userName.setEditable(true);
userName.setRequired(true);
userName.setTooltip("Please enter the userName");
// userName.placeAt("userName");
var passWord = new sap.ui.commons.PasswordField("Password");
passWord.setEnabled(true);
passWord.setEditable(true);
passWord.setVisible(true);
passWord.setRequired(true);
passWord.setTooltip("Please enter the password");
// passWord.palceAt("password");
var button = new sap.ui.commons.Button("submitBtn");
button.setText("Submit");
button.attachPress(oController.validateCredentials)
userName.placeAt('shell1');
passWord.placeAt('shell1');
button.placeAt('shell1');
/*aControls.push(userName);
aControls.push(passWord);
aControls.push(button.attachPress(oController.validateCredentials));*/
//return aControls;
//Function in JS File :
//oShell.setContent(sap.ui.getCore().byId("listView"));
}
});
LOGINPAGE CONTROLLER
sap.ui.controller("testlogin.loginpage", {
/**
validateCredentials : function(oEvent){
var oModel = new sap.ui.model.json.JSONModel();
var userName = sap.ui.getCore().byId("UserName").getValue();
var password = sap.ui.getCore().byId("Password").getValue();
/**/
if(userName == ""){
alert("ERROR - UserName is required");
}else if(password == ""){
alert("ERROR - Password is required");
}else {
alert("Welcome : " + userName);
/*
var data = {
names : [{
firstName: sap.ui.getCore().byId("UserName").getValue()
}]
};*/
oModel.setData({
countries : [ {
countryname : "India"
}, {
countryname : "England"
}, {
countryname : "Germany"
}]
});
sap.ui.getCore().setModel(oModel,"myModel");
alert(sap.ui.getCore().getModel("myModel").getProperty("/countries")[0]["countryname"]) ;
// sap.ui.getCore().byId("shell1").removeAllWorksetItems();
sap.ui.getCore().byId("shell1").setContent(sap.ui.getCore().byId("welcomeView"),true);
// oShell.setContent(sap.ui.getCore().byId("idsecondView1"));
}
}
});
WELCOME PAGE VIEW
sap.ui.jsview("testlogin.welcomepage", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf testlogin.welcomepage
*/
getControllerName : function() {
return "testlogin.welcomepage";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* @memberOf testlogin.welcomepage
*/
createContent : function(oController) {/*
var oModel = sap.ui.getCore().getModel("myModel");
var data = oModel.getProperty("/countries/countryName");
//alert(data);
var oLabel = new sap.ui.commons.Label({
id : "myLabel", // sap.ui.core.ID
text : 'Hello', // string
});
//alert("Page2loading");
//return sap.ui.getCore().byId("idPage21");//.placeAt("content");
return oLabel;
*/
var oModelSt= new sap.ui.model.json.JSONModel();
oModelSt.setData(sap.ui.getCore().getModel("myModel"));
var tt=sap.ui.getCore().getModel("myModel");
var oLabel = new sap.ui.commons.Label({
id : "myLabel", // sap.ui.core.ID
text : 'Hello '+tt // string
});
return oLabel;
}
});