03-07-2013 12:55 PM
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
config.setProperty(BrowserFieldConfig.JAVASCRIPT_E
config.setProperty(BrowserFieldConfig.NAVIGATION_M
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
03-07-2013 02:18 PM
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/blackbe
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
config.setProperty(BrowserFieldConfig.JAVASCRIPT_E
config.setProperty(BrowserFieldConfig.NAVIGATION_M
_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(BrowserField
_request = request;
}