Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Regular Contributor
annuk
Posts: 82
Registered: ‎09-26-2012
My Device: Torch 9800
My Carrier: NA

How to retrieve data passed in bb.pushScreen

Hi,

 

How do we retrieve the data passed in bb.pushScreen on another page.

 

When i do bb.pushScreen('js/mylibs/templates/synopsis.html','synopsis',{"synopsis":"details page"});

 

What should i do in synopsis.html to get the parameters?

 

Please help.

 

Regards,

Annuk

Please use plain text.
Developer
The_Anomaly
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: How to retrieve data passed in bb.pushScreen

1.  I created a variable in the main index.html, before the bb.init code.

2.  I then dynamically create a page that lists my data and sets the var (from a database)

 

listItem.setAttribute('onclick', 'fs_id = "' + itemKey + '";

3.  Clicking on the link will set the var and push the page.

4.  The new page will check the var and apply any needed code.

 

I guess for a simple app you could do:

 

onclick="myVar=myParam;bb.pushScreen('myhtmlpage.html', 'myhtmlid');"

myVar would need to be declared in the index.html...

If it helped you, click like. :smileyhappy:
Please use plain text.
Administrator
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: How to retrieve data passed in bb.pushScreen

hi annuk,

 

This is documented in the "Screens" page within the bbUI wiki site:

 

https://github.com/blackberry/bbUI.js/wiki/Screens

 

"This third optional parameter will then be passed into the onscreenready and ondomready events (provided in the toolkit initialization) when they fire for the associated screen"

 

So you'll need to establish a handler for the onscreenready and ondomready events. Details here:

https://github.com/blackberry/bbUI.js/wiki/Toolkit-Initialization

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.
Regular Contributor
annuk
Posts: 82
Registered: ‎09-26-2012
My Device: Torch 9800
My Carrier: NA

Re: How to retrieve data passed in bb.pushScreen

Hi astanley,

 

Thanks for your reply. Did as you said. I want to retrieve the passed parameter in another html. How do I retrieve it? I added a javascript function for setting the value of the parameter.

 

My code:index.html

<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>SAMPLE</title>
		<meta name="x-blackberry-defaultHoverEffect" content="false" />
		<link  rel="stylesheet" type="text/css" href="bbui-0.9.4.css">
		<link />
		<script type="text/javascript" src="bbui-0.9.4.js"></script>
		<script type="text/javascript" src="js/webworks-1.0.2.9.js"></script>
		<script type="text/javascript">
			document.addEventListener('webworksready', function(e) {
				// For some fun I did some random color scheme generation :o)
				var highlightColor, randomNumber;
				randomNumber = Math.floor(Math.random() * 100);
				if (randomNumber > 90) {
					highlightColor = '#BA55D3';
				} else if (randomNumber > 60) {
					highlightColor = '#00BC9F';
				} else if (randomNumber > 30) {
					highlightColor = '#00A8DF';
				} else {
					highlightColor = '#B2CC00';
				}

				// You must call init on bbUI before any other code loads.
				// If you want default functionality simply don't pass any parameters.. bb.init();
				bb.init({
					actionBarDark : true,
					controlsDark : true,
					listsDark : false,
					bb10ForPlayBook : false,
					highlightColor : highlightColor,
					// Fires "before" styling is applied and "before" the screen is inserted in the DOM
					onscreenready : function(element, id,param) {
						if (id == 'dataOnLoad') {
							dataOnLoad_initialLoad(element);
						} else if (id == 'masterDetail') {
							masterDetail_initialLoad(element);
						}

						// Remove all titles "except" input and pill buttons screen if running on BB10
						if (bb.device.isBB10 && (id != 'input') && (id != 'pillButtons')) {
							var titles = element.querySelectorAll('[data-bb-type=title]');
							if (titles.length > 0) {
								titles[0].parentNode.removeChild(titles[0]);
							}
						}

						if (id == 'sample') {
							console.log('id is sample in onscreenready');
							if (param != null) {
								//alert(param.name);
								addData(element, param);
							}
						}

					},
					// Fires "after" styling is applied and "after" the screen is inserted in the DOM
					ondomready : function(element, id) {
						if (id == 'dataOnTheFly') {
							alert('Data on the fly');
						}
					}
				});
				bb.pushScreen('sample.html', 'sample',{'name':'annuk'});
			}, false);
		</script>
	</head>
</html>

 

The index.html calls the onScreenReady function twice.
I get the logs twice.

Logs:

Ripple :: Environment Warming Up (Tea. Earl Gray. Hot.) ripple.js:475
webworks.bb10 :: Initialization Finished (Make it so.) ripple.js:475
id is sample in onscreenready index.html:51
in sample.js addData [object Object] browse.js:23
value is [object Object] browse.js:25
webworks.bb10 :: fired webworksready event! ripple.js:475
id is sample in onscreenready index.html:51
in sample.js addData [object Object] browse.js:23
value is [object Object] 

 

 

 My js file:

 

var value;

function addData(element, param) {
	console.log('in sample.js addData ' + param);
	this.value = param;
	console.log('value is '+value);
}

function getData() {
	console.log('in sample.js getData ' + this.value);
	return this.value;
}

 

How do I retreive it in sample.html? Where am i going wrong?

 

Regards,


Annuk

Please use plain text.