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
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

how to pass parameter from javascipt to java

Hi,

I want to get parameter from javascipt to java

 

This is my code javascipt used on java

 

String finalpart = 

 " for (i = 0; i < locations.length; i++) { \r\n" +
" marker = new google.maps.Marker({\r\n" +
 " position: new google.maps.LatLng(locations[i][1], locations[i][2]),\r\n" +
" map: map\r\n" +
 " });\r\n" +
"\r\n" +
" google.maps.event.addListener(marker, 'click', (function(marker, i) {\r\n" +
 " return function() {\r\n" +
 " infowindow.setContent(locations[i][0]);\r\n" +
 " infowindow.open(map, marker);\r\n" +
" }\r\n" +
" })(marker, i));\r\n" +
" }\r\n" +

 I wnat to get the value locations[i][0] to use it on java class

locations[i][0]
Contributor
Posts: 44
Registered: ‎12-01-2009
My Device: Not Specified

Re: how to pass parameter from javascipt to java

I believe the Extensions lab shows how to pass in a parameter to a function.. It passes in the duration of the vibrate as an example.

http://na.blackberry.com/eng/developers/devbetasoftware/Lab_Widget_Extension.zip
Developer
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Re: how to pass parameter from javascipt to java

When you implement your Javascript Extension, you can pass arguments to the "java part" like you would with any other function. For example, say you are calling: sandbox.example.doSomething()

 

In it's Scriptable Function class, you would normally have:

 public Object invoke(Object obj, Object[] args) throws Exception {
			String location = ((String)args[0]);

 This way you can call  sandbox.example.doSomething(locations[i][0] )  and pass locations[i][0] to it.

 


Wadi
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: how to pass parameter from javascipt to java

Hi Wantoun,

I didn't get you. What you mean. What should I add in code javascript. I wnat to add like String val=locations[i][0] and then I use val in my code java

Developer
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Re: how to pass parameter from javascipt to java

Are you familiar with Javascrpt Extensions? You can find more about it here: https://bdsc.webapps.blackberry.com/html5/documentation/ww_developing/using_javascript_extensions_18...

 

I assumed you do since you were dealing with Java AND javascript.

You would then be able to pass "val" to the java by simply calling the javascript etension that you made and passing it.

Let me know if it's still not clear after you check the link.

Wadi