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
Highlighted
New Contributor
Posts: 9
Registered: ‎10-19-2010
My Device: 9700
Accepted Solution

Initialize BrowserField object in JS Extension

Hi,

 

I found a very useful post for my scenario at 

http://supportforums.blackberry.com/t5/Web-Development/Widget-Javascript-Extension-Callback/m-p/4725...

 

As per the reply from Adam, we can do callback in JS extension using below piece of code,

 

 

ScriptableFunction _myFunc = new ScriptableFunction() 
{
   public Object invoke(Object obj, Object[] args) throws Exception
   {
      if (args.length == 2) {
         int param1 = ((Integer)args[0]).intValue();
         int param2 = ((Integer)args[1]).intValue();
         _browserField.getScriptEngine().executeScript("add(" + param1 + ", " + param2 + ")", null);
      }
      return UNDEFINED;
   }
};  

 

 

Can anyone tell me how one can initialize the "_browserField" object in Java, or is this to be passed as argument to the JS Extension call.

 

Thanks in advance,

Ziya.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Initialize BrowserField object in JS Extension

Hi Ziya,

 

There is actually an even easier way to perform a callback into your javascript.  What you can do is something like the following pseudo code:

 

 

ScriptableFunction _myFunc = new ScriptableFunction() 
{
   public Object invoke(Object obj, Object[] args) throws Exception
   {
      if (args.length == 2) {
         int param1 = ((Integer)args[0]).intValue();
         int param2 = ((Integer)args[1]).intValue();
         ScriptableFunction add = (ScriptableFunction)args[3];
         add.invoke(add, [param1, param2]);
      }
      return UNDEFINED;
   }
};  

 

Basically you can actually pass in a JavaScript function as a parameter for a callback.  You can then hold the handle to the ScriptableFunction and then call its invoke just like your own ScriptableFunction is called.

 

It is much cleaner and allows you to actually hold a pointer to the instance of the add function you are wanting to call.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
New Contributor
Posts: 9
Registered: ‎10-19-2010
My Device: 9700

Re: Initialize BrowserField object in JS Extension

Thanks a ton Tim.

 

It works great, and now I have handle of the callback function.

 

Thanks again.

 

Cheers.

Contributor
Posts: 12
Registered: ‎02-09-2011
My Device: Not Specified

Re: Initialize BrowserField object in JS Extension

Hi tneil,

 

Can I call from javaScript extension to java native to launch new UI component? 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Initialize BrowserField object in JS Extension

Yes you can.  However you will likely need to restrict this to creating a new Screen object with UI on it.  You won't be able to embed a new UI element into the HTML view of the page.

 

As an example you can check out my Spinner control:

http://supportforums.blackberry.com/t5/BlackBerry-WebWorks/API-Candidate-Spinner-Control/td-p/634388

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 12
Registered: ‎02-09-2011
My Device: Not Specified

Re: Initialize BrowserField object in JS Extension

I have build BB app that have title bar and footer bar. It works well with iPhone and Android and I use web technology, PhoneGap+jQTouch+iScroll to make the content scrollable. but I test on simulator it doesn't work on BB. how can I solve problem with scrollable content in WebWork?

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Initialize BrowserField object in JS Extension

Hi chandara,

 

Can you provide some more details of what you are trying to accomplish with scrolling?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 12
Registered: ‎02-09-2011
My Device: Not Specified

Re: Initialize BrowserField object in JS Extension

Hi

 

I want to build app in BlackBerry 5, 6. I used webwork blackberry and it build from jQTouch + iScroll to make app like in iPhone and Android that have TitleBar, FooterBar and Scrollable Content when overflow.

 

I test BlackBerry WebWork it work on OS 6 and it's scrollable when have overflow content. but in BlackBerry OS 5 no way althought I try with jQuery Mobile. How should I do with scrollable content?

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: Initialize BrowserField object in JS Extension

hi i create some javascript extension 

like  this tutorial : http://supportforums.blackberry.com/t5/tkb/articleprintpage/tkb-id/browser_dev@tkb/article-id/45

 to call socket and listen messages from server.... if have new message  execute socketMessage(msg); javascript function

following my code :

 

package connections;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.system.CoverageInfo;
import javax.microedition.io.Connector;
import java.lang.String;
import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import net.rim.device.api.script.ScriptableFunction;
import javax.microedition.io.StreamConnection;
import net.rim.device.api.ui.component.Dialog;
public final class SocketFunction extends ScriptableFunction {
    private static String URL = "socket://192.168.1.105:8790;deviceside=false";

  public Object invoke(Object obj, Object[] args) throws Exception
  {
  StreamConnection conn = null;
  conn = (StreamConnection)Connector.open(URL);
 
  OutputStreamWriter _out = new OutputStreamWriter(conn.openOutputStream());
  String data = "This is a test --->";
  _out.write(data);
 
  InputStreamReader _in = new InputStreamReader(conn.openInputStream());
  StringBuffer sb = new StringBuffer();
  int c = 0;
       while (((c = _in.read()) != '\n') && (c != -1)) {
          sb.append((char) c);
       }
      

        //ScriptableFunction socketMessage = (ScriptableFunction)args[3]; 
        //socketMessage.invoke(socketMessage,[sb.toString(), null]);// this not work I don't know how to do ?? because parameter only 1

        _browserField.getScriptEngine().executeScript("socketMessage(" + sb.toString() + ")", null); // how to initsialize _browserField

  _in.close();
  _out.close();
  conn.close();
  return sb;
  }
}

 

 

 

The problem :
1.socketMessage(msg) never executes;
2. I don't know socket listening server message or not...
really appreciate for assistance
Thanks
Sondang

 

Contributor
Posts: 21
Registered: ‎04-23-2011
My Device: 9700
My Carrier: xl

Re: Initialize BrowserField object in JS Extension

anyone can help me pleaseee


Thanks
Sondang