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
New Contributor
dew777
Posts: 4
Registered: ‎03-06-2013
My Device: Torch 9850

BrowserField2 handleNavigation event

To all, I posted this yesterday in the "java development" section but now realize it probably belongs in this area. My appologies for the double-post.

 

I'm working with the "BrowserField2Demo" in JDE 7.1 and and trying to intercept the "handleNavigationRequest" event for a re-direct. At this time I'm not trying to change the URL but simply am trying to get something to work.

The problem is that when I run it on my Torch 9850 I get a pop-up error message:
Error requesting content for:
http://google.com
Error message
null
<CLOSE>

If I remove the "ProtocolController" function (and registration) the code works correctly. But if I use the "controller" I get the "null" error. Any suggestions as to what I'm doing wrong?

Here is my code:
private BrowserField _browserField;
private boolean _documentLoaded = false;
private BrowserFieldRequest _request;

/**
* Creates a new BrowserFieldScreen object
* @param request The URI of the content to display in this BrowserFieldScreen
* @param enableScriptMenu True if a context menu is to be created for this BrowserFieldScreen instance, false otherwise
*/
public BrowserFieldScreen(BrowserFieldRequest request, boolean enableScriptMenu)
{
super(Screen.HORIZONTAL_SCROLL);

BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
config.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
config.setProperty(BrowserFieldConfig.CONTROLLER, controller);
_browserField = new BrowserField(config);
add(_browserField);
_request = request;
}

ProtocolController controller = new ProtocolController(_browserField)
{
public void handleNavigationRequest(BrowserFieldRequest request) throws Exception
{
InputConnection inputConnection = handleResourceRequest(request);
_browserField.displayContent(inputConnection, request.getURL());
}
};

Thanks in advance for your advice!
dew

Please use plain text.
New Contributor
dew777
Posts: 4
Registered: ‎03-06-2013
My Device: Torch 9850

Re: BrowserField2 handleNavigation event

To anyone who was puzzled by this I have a working solution:

 

I found a post on stackoverflow that suggested that the getting the browserField2 initialized BEFORE setting up the eventProtocolController was important (link: http://stackoverflow.com/questions/9466155/blackberry-facebook-sdk-login-browser-error ).

 

It now works on my 9850. 

 

Code:

public BrowserFieldScreen(BrowserFieldRequest request, boolean enableScriptMenu)
{
super(Screen.HORIZONTAL_SCROLL);

addKeyListener(new BrowserFieldScreenKeyListener());

BrowserFieldConfig config = new BrowserFieldConfig();
config.setProperty(BrowserFieldConfig.ALLOW_CS_XHR, Boolean.TRUE);
config.setProperty(BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE);
config.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_browserField = new BrowserField(config);
_browserField.addListener(new DemoBrowserListener());
add(_browserField);

ProtocolController eventsProtocolController = new ProtocolController(_browserField)
{
public void handleNavigationRequest(BrowserFieldRequest request) throws Exception
{
String tempURL = request.getURL();

if ( tempURL.endsWith( "bing.com" ) )
{
request.setURL( "http://google.com" );
}

_browserField.setFocus();
super.handleNavigationRequest(request);
}
};
_browserField.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, eventsProtocolController);

_request = request;
}

 

 

Please use plain text.