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
Contributor
Posts: 11
Registered: ‎07-30-2012
My Device: 9900
My Carrier: work

Getting URL From BrowserField

[ Edited ]

I am trying to create a method that executes every time a link changes within a BrowserField.  To do this I extended ProtocolController and implemented handleNavigationRequest. When the BrowserField.requestContent method executes the main page loads and handleNavigationRequest executes.  When a link at the same address is selected it does not execute.  If, however, the address changes then it works (the method executes).

 

Example:

1) browserField.requestContent("http://myCompany.com/index.html).  handleNavigationRequest executes.

2) click on link in browser field that references same server address: "http://myCompany.com/link1/link.html".  handleNavigationRequest does not execute.

3) click on link in browser field that references external site: http://google.com.  handleNavigationRequest executes.

 

The problem is that I need the method to execute every time a link is selected, even if it's on the same server. 

 

Here is the code in the constructor of the UI screen that sets up the browser field:

config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED,Boolean.TRUE);

  

_browserField = newBrowserField(config);

_browserField.getConfig().setProperty(BrowserFieldConfig.CONTROLLER,newBrowserController_browserField));

 

add(_browserField);

_browserField.requestContent(http://myCompany.com/index.html);

 

Here is the ProtocolController class that implements handleNavigationRequest

 

public class BrowserController extendsProtocolController

{

private String URL_TO_TRAP = "http://us.blackberry.com/devices.html";

 

public BrowserController(BrowserField browserField)

{

   super(browserField);

}

 

publicvoid handleNavigationRequest(BrowserFieldRequest request) throwsException

{

 

    if(request.getURL().equals(URL_TO_TRAP) )

    {

           //custom action here

      }

    super.handleNavigationRequest(request);

     \}

 

}

 

The code is based on a sample I found.  Am I using the right approach?

Thanks in advance for any assistasnce.

 

 

Contributor
Posts: 11
Registered: ‎07-30-2012
My Device: 9900
My Carrier: work

Re: Getting URL From BrowserField

Anybody?