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

Java Development

Reply
Highlighted
Contributor
Posts: 15
Registered: ‎06-11-2010
My Device: NA
My Carrier: NA

how to call a javascript function from java while passing parameters

I need to call a javascript function from java code along with parameters.

I have studied the sample code 'BrowserField2Demo' supplied with the JDE.

 

There for example getBrowserField().getScriptEngine().executeScript("submitSearch()", null); is called to call the function submitsearch() of javascript.

I want to pas some arguments in submitsearch.How to do that

New Contributor
Posts: 9
Registered: ‎03-31-2011
My Device: 9700

Re: how to call a javascript function from java while passing parameters

hi 

 

have u found any way to solve this problem.....?

 

 

 

Deeps
New Developer
Posts: 134
Registered: ‎01-11-2011
My Device: curve

Re: how to call a javascript function from java while passing parameters

package com.script;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.b...


































 

 

 

 

 

 

 

 

and the other one is

 

 

package com.script;

import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
    public MyScreen()
    {        
        // Set the displayed title of the screen       
        //setTitle("Javascript Proof of Concept");
    }
}

New Developer
Posts: 134
Registered: ‎01-11-2011
My Device: curve

Re: how to call a javascript function from java while passing parameters

package com.script;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldListener;
import net.rim.device.api.ui.UiApplication;

public class MyApp extends UiApplication
{
    BrowserField _bf2;    
 
    public static void main(String[] args)
    {       
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }  
 
    public MyApp()
    {
        final MyScreen _screen = new MyScreen();        
        
        _bf2 = new BrowserField();
        BrowserFieldListener listener = new BrowserFieldListener()
        {
             public void documentLoaded(BrowserField browserField, org.w3c.dom.Document document) throws Exception
             {
                 String strReturnValue = (String)_bf2.executeScript("javascript: GetJavascriptVariable()");
                 _screen.setTitle(strReturnValue);
             }
         };
         _bf2.addListener( listener );
        
        _screen.add(_bf2);        
        
        _bf2.requestContent("http://uat.liverx.com/test.html");   
        
        
        pushScreen(_screen);
    }    
}