Skip to Content
0
Former Member
Jul 31, 2014 at 04:15 AM

Passing Parameters between two pages in SAPUI5

604 Views

Hi,

In my SAPUI5 Application, i have two views, first one is Login page & second one is a Master-Detail page displaying PurchaseOrders.

The Login page & Master detail are working fine as two separate pages. But the actual requirement is to pass the Login information from Login page to Masterdetail page.

We validate the user role & access & then based on these values we take the user to the second page.

For this validation we hit ODATA service in Login page's Controller like below:

I hit the service & i get the RelCode & RelGroup from the response. I need to pass these values to my second page. I have gone through various forums & apis & found that the new functionality "subscribe" & "channel" will help pass data between pages. But i couldn't get this implementation right, with very few references available.

It would be of great help if anyone can suggest a logic to pass data between pages... Appreciate any assistance!!

LoginPagecontroller.js:

login_validate : function(oEvent)

{

try

{

//alert('1');

var username_value = $("#username_value_id").val();

alert('username_value '+username_value);

var password_value = $("#password_value_id").val();

alert('password_value '+password_value);

var login_url = "proxy/http/incas1054.ind.cldsvc.accenture.com:8000/sap/opu/odata/sap/ZDP_MOBILE_ACCESS_SRV/LOGINACCESSSet(Uname='"+username_value+"',Password='"+password_value+"')";

var login_Odatamodel = new sap.ui.model.odata.ODataModel(login_url, "dev_sde", "28aug@2013");

sap.ui.getCore().setModel(login_Odatamodel);

var RelCode = "";

var RelGroup = "";

OData.request({

requestUri : login_url,

method : "GET",

user: username_value,

password: password_value,

headers :

{

"X-Requested-With" : "XMLHttpRequest",

"Content-Type": "application/json; charset=utf-8",

"DataServiceVersion" : "2.0",

"X-CSRF-Token" : "Fetch"

}

},

function(data, response)

{

RelCode = data.RelCode;

RelGroup = data.RelGroup;

var oBus = sap.ui.getCore().getEventBus();

var params = {param1: RelCode};

//to subscribe

oBus.subscribe("myChannel","ToDetailPage",show);

//to publish data between pages

oBus.publish("myChannel","ToDetailPage",params);

},

function(err)

{

alert('Error Caught '+err.message);

}

);

}

catch(err)

{

alert('error '+error.message);

}

}

Loginpageview.js: On Logon, the page navigation is set to 2nd page. This is where i need to pass those parameters as described above.

Logon_btn = new sap.ui.commons.Button(

{

id:"logon_btn",

text: "Login",

tooltip : "Login Here",

press : function(evt)

{

if($("#username_value_id").val().length != 0 && $("#password_value_id").val().length != 0)

{

oController.login_validate();

var app = sap.ui.getCore().byId("po_id");

app.to("idPurchaseOrder1");

//alert('end');

}

else

{

alert("Please Enter Valid Credentials.");

}

}

})

----

An update to my question:

I am able to subscribe & publish the data to the second page. But i now need to know how i can set this in my ODATA URL of master/detail page:

The code below shows the RelCode i retrieved from login page's response:

createContent : function(oController) {

var RelCode = "";

DetailHome = function(sChannelId, sEventId, oData){

//var RelGroup = "";

RelCode = oData.param1;

alert('RelCode in PO --'+RelCode);

};

}

The above RelCode need to be passed to the Master page's service URL..

var masterServiceUrl = "proxy/http/incas1054.ind.cldsvc.accenture.com:8000/sap/opu/odata/sap/Z_PO_ORDER1_SRV/?RelGroup='RG'ℜlCode='"+RelCode+"'";